; File: macros.scm ; Title: Macros with variable number of arguments ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;(f1 1 2 3 4 5) -> (2 3 4 5) ;(f1 'a) ->() (define-macro f1 (lambda (x . L) `(list ,@L) )) ; (f2 1 2 3 4 5) -> (1 2 3 4 5) (define-macro f2 (lambda (x . L) `(list ,x ,@L) )) ; Sometimes put 3 dots to indicate more args Ex: x... ; > (mm 2 3 4 5) -> (2 3 4 5) (define-macro m0 (lambda x... `(list ,@x...))) ;(myprint "hello\n" 2006 "\nBye") ; hello ; 2006 ; Bye (define-macro myprint (lambda L `(for-each display L) )) ;;;;;same as: (define-macro myprint0 (lambda ( x . L ) `(for-each display (list ,x ,@L)) )) ; (myand 2 3 4 'a) -> a (define-macro myand (lambda L `(and ,@L) )) ; (when pred do1 do2 ..) else do-nothing ; Example: (when (number? 3)( display 3) (display 4) (display 'hi)) ->34hi (define-macro when (lambda (p . L) `(cond (,p ,@L)) ) )