; ; absurd contrived exaggerated example to test that macros that generate ; macros that generate macros that generate expressions are likely to work ; ; may you never need to do this in real life ; (mac make-make-op (opname op) `(mac ,opname (name n . body) `(mac ,name (x) `(,',',op ,,n ,x)))) (make-make-op make-mult *) (make-make-op make-plus +) (make-mult *five 5) (make-mult *seven 7) (make-mult *eleven 11) (make-plus +five 5) (make-plus +seven 7) (make-plus +eleven 11) (register-test '(suite "Boot Tests" (suite "quasiquote" ("peeks inside nested quotes" `(a b '(c ,(+ 1 2))) (a b '(c 3))) ("handles nested unquote-splicing" ``(a ,,@(list '+ 1 2) b) `((a ,(+ 1 2) b))) ("returns nested quasiquotes" `(a b `(c d ,(+ 1 2) ,,(+ 3 4))) (a b `(c d ,(+ 1 2) ,7)))) (suite "build-keyword-args" ("takes a list of lists and returns the list with the first item of each sublist quoted" (build-keyword-args '( (a 1) (b c) (d e "f" 22) )) ((list 'a 1) (list 'b c) (list 'd e "f" 22)))) (suite "make-macros can create macros" ("make-plus example generates a plus-seven expression" (+seven 6) 13) ("make-mult example generates a multiply-by-seven expression" (*seven 6) 42) ("make-mult example generates a multiply-by-eleven expression" (*eleven 20) 220) ("make-make example expressions can be nested" (*eleven (*five (+seven 2))) 495))))