Next: , Previous: , Up: iklib syntaxes   [Index]


6.8.3 define–like additional syntaxes

Syntax: case-define ?who ?cl-clause0 ?cl-clause

Convenience syntax which expands as follows:

(case-define ?who ?cl-clause0 ?cl-clause …)
→ (define ?who
      (case-lambda ?cl-clause0 ?cl-clause …))
Syntax: define* ?who ?expression
Syntax: define* ?who
Syntax: define* (?who . ?formals) ?body0 ?body
Syntax: define* (?pred-who . ?formals) ?body0 ?body

Like the standard define as defined by R6RS, but when defining a function: allow the specification of logic predicates to validate the arguments and return values.

Logic predicates specification is performed as explained for the lambda* extended syntax (see iklib syntaxes lambdas). There is an exception, where lambda* uses the _ symbol to select predicates for the returned values, define* uses the binding identifier ?who.

In addition, when defining a function or a variable with non–empty right–hand side, the fluid identifier syntax __who__ is bound to the quoted symbol ?who.

Usage examples:

Syntax: case-define* ?who ?pred-cl-clause0 ?case-clause

Convenience syntax that expands to something similar to:

(case-define* ?who ?pred-cl-clause0 ?pred-cl-clause …)
→ (define ?who
      (case-lambda* ?pred-cl-clause0 ?pred-cl-clause …))

In addition the fluid identifier syntax __who__ is bound to the quoted symbol ?who.

Syntax: define-values ?formals ?form0 ?form

Evaluate the given forms and bind the, possibly multiple, result of the last one to the given ?var identifiers. formals has the same syntax of the lambda formals.

(define-values (a b c)
  (values 1 2 3))

(list a b c)    ⇒ (1 2 3)
Syntax: define-constant-values formals ?form0 ?form

Evaluate the given forms and bind the, possibly multiple, result of the last one to the given formals identifiers; make the formals identifiers immutable. formals has the same syntax of the lambda formals.

(define-constant-values (a b c)
  (values 1 2 3))

(list a b c)    ⇒ (1 2 3)
(set! a 99)     error→ &syntax
Syntax: define-inline (?name ?arg … . ?rest) ?body0 ?body

Similar to define, but create a binding that is always expanded inline and can neither be invoked recursively nor used as function rgument. This syntax only defines a syntax.

(define-inline (incr x)
  (+ x 1))

(incr 2)        ⇒ 3

In the example above, we can think of (incr 2) as expanding to:

(let ((x 2))
  (+ x 1))
Syntax: define-inline-constant ?name ?expr

?expr is evaluated only once at expand time, the result is returned by the macro transformer bound to ?name. It is impossible to modify the result of the expansion of ?name by acting upon ?name.

Syntax: define-integrable (?name ?arg … . ?rest) ?body0 ?body

Similar to define, but create a binding that is always expanded inline and can be both invoked recursively and used as function argument. This syntax defines both a syntax and a function.

(define-integrable (incr x)
  (+ x 1))

(incr 2)
⇒ 3

(map incr '(10 20 30)))
⇒ (11 21 31)

In the example above, we can think of (incr 2) as expanding to:

((lambda (x)
   (+ x 1))
 2)

Next: , Previous: , Up: iklib syntaxes   [Index]