20-CS-4003-001 Organization of Programming Languages Fall 2017
Define-Syntax examples

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

Define-syntax (macros)

;; doit followed by any sequence returns a list of 
;; elements of the sequence.
(define-syntax doit
  (syntax-rules ()
    ((doit a ...) (list a ...))))
 -  The define-syntax special form makes use of ellipses (...) to express an expansion of lists of objects compactly. What is interesting in the basic example to the left is that doit can be applied to any kind of object, not just quoted atoms or strings. For example,
  prompt> (doit (lambda () 1) 'john cons)
  ;Value 67: (#[compound-procedure 14] 
              #[compiled-procedure 15 
                 ("list" #x3) #xc #x12f995c])