Next: , Previous: , Up: Syntax   [Contents][Index]

Primitive expression syntax

expression ::= literal-expression | variable-reference
  | procedure-call | TODO

Literal expressions

literal-expression ::= (quote datum)
  |  datum
  | constant 
constant ::= number | boolean | character | string

(quote datum) evaluates to datum, which may be any external representation of a Scheme object. This notation is used to include literal constants in Scheme code.

(quote a)               ⇒  a 
(quote #(a b c))        ⇒  #(a b c)
(quote (+ 1 2))         ⇒  (+ 1 2)

(quote datum) may be abbreviated as 'datum. The two notations are equivalent in all respects.

’a                      ⇒  a
’#(a b c)               ⇒  #(a b c)
’()                     ⇒  ()
’(+ 1 2)                ⇒  (+ 1 2)
’(quote a)              ⇒  (quote a)
’’a                     ⇒  (quote a)

Numerical constants, string constants, character constants, bytevector constants, and boolean constants evaluate to themselves; they need not be quoted.

145932          ⇒  145932
#t              ⇒  #t
"abc"           ⇒  "abc"

Note that keywords need to be quoted, unlike some other Lisp/Scheme dialect, including Common Lisp, and earlier versions of Kawa. (Kawa currently evaluates a non-quoted keyword as itself, but that will change.)

Variable references

variable-reference ::= identifier

An expression consisting of a variable is a variable reference if it is not a macro use (see below). The value of the variable reference is the value stored in the location to which the variable is bound. It is a syntax violation to reference an unbound variable.

The following example assumes the base library has been imported:

(define x 28)
x   ⇒  28

Procedure calls

procedure-call ::= (operator operand …)
operator ::= expression
operand ::= expression
  | keyword expression
  | @ expression
  | @: expression

A procedure call consists of expressions for the procedure to be called and the arguments to be passed to it, with enclosing parentheses. A form in an expression context is a procedure call if operator is not an identifier bound as a syntactic keyword.

When a procedure call is evaluated, the operator and operand expressions are evaluated (in an unspecified order) and the resulting procedure is passed the resulting arguments.

(+ 3 4)                ⇒  7
((if #f + *) 3 4)      ⇒  12

The syntax keyword expression is a keyword argument. This is a mechanism for specifying arguments using a name rather than position, and is especially useful for procedures with many optional paramaters. Note that keyword must be literal, and cannot be the result from evaluating a non-literal expression. (This is a change from previous versions of Kawa, and is different from Common Lisp and some other Scheme dialects.)

An expression prefixed by @ or @: is a splice argument. The following expression must evaluate to an “argument list” (see Application and Arguments Lists for details); each element in the argument becomes a separate argument when call the operator. (This is very similar to the “spread” operator is EcmaScript 6.)


Next: , Previous: , Up: Syntax   [Contents][Index]