Next: iklib syntaxes defstxs, Previous: iklib syntaxes lambdas, Up: iklib syntaxes [Index]
define
–like additional syntaxesConvenience syntax which expands as follows:
(case-define ?who ?cl-clause0 ?cl-clause …) → (define ?who (case-lambda ?cl-clause0 ?cl-clause …))
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:
#!vicare (import (vicare)) (define* (f {a number?} {b number?}) (list (number->string a) (number->string b))) (f 1 2) ⇒ ("1" "2")
#!vicare (import (vicare)) (define* (f {a number?} {b number?} . {rest number?}) (list (number->string a) (number->string b) (length rest))) (f 1 2 3 4 5) ⇒ ("1" "2" 3)
#!vicare (import (vicare)) (define* (f . {args number?}) (length args)) (f 1 2 3) ⇒ 3
#!vicare (import (vicare)) (define* ({f fixnum?} val) val) (f 1) ⇒ 1
#!vicare (import (vicare)) (define* ({f fixnum? string?} a b) (values a b)) (f 1 "2") ⇒ 1, "2"
(import (vicare)) (define* (f) __who__) (f) ⇒ f
(import (vicare)) (define* a (list 'name __who__)) a ⇒ (name a)
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.
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)
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
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))
?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.
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: iklib syntaxes defstxs, Previous: iklib syntaxes lambdas, Up: iklib syntaxes [Index]