(syntax object object ...) | Creates a syntactic procedure. It has the same syntax as lambda.
Returns the created syntax. |
(syntax? object) | Returns #t if 'object' is a syntax. begin, define, let, if ... and objects created by method and syntax-method are syntactic objects. A syntax is also a procedure. |
(syntax-method object object ...) | Creates a syntactic method. It has the same syntax as method.
Returns the created syntax. |
(define while
(syntax (c . L)
(if (local-eval
c)
(begin
(apply begin L)
(apply while c L)))))
Now we can use it to make iterations:
(let ((n 0))
(while (< n 5)
(display n)
(set! n (+ n 1))))
The evaluation of the previous expressions produces the output :
01234
an returns an unspecified value.
The next example shows how to use syntax-method. This syntax is a method of the class <object> that gets a method of the class of the current object (see the object model of the scheme package for more details).
(<object> define get-method
(syntax-method (name)
(apply (<class> get
get) (this get-class) name '())))
Now we can use it in the following way:
(define obj (<object> make))
(obj get-method get-class) ==> #[method get-class]