Skip to content

Instantly share code, notes, and snippets.

@edw
Last active May 18, 2020 15:41
Show Gist options
  • Save edw/1c663281adb06769b1d7b68971253f00 to your computer and use it in GitHub Desktop.
Save edw/1c663281adb06769b1d7b68971253f00 to your computer and use it in GitHub Desktop.
A working but not recommended macro
;;; This is not a good use of macros. See below for an
;;; example implementation of COND.
(define-syntax proc-all
(syntax-rules ()
((_ exp () body ...)
(begin body ...))
((_ exp (match matches ...) body ...)
(unless (= exp match) (proc-all exp (matches ...) body ...)))))
;;; Example
(proc-all 4 (3 2 1) (display "4 is not 3, 2, or 1.") (newline))
;; Prints the message.
(proc-all 2 (3 2 1) (display "4 is not 3, 2, or 1.") (newline))
;; Does not print the message.
;;; Something less crazy (COND including ELSE and => features)
(define-syntax my-cond
(syntax-rules (else =>)
((_) (begin))
((_ (else body ...)) (begin body ...))
((_ (test => proc) clauses ...)
(let ((result test))
(if result
(proc result)
(my-cond clauses ...))))
((_ (test body ...) clauses ...)
(if test (begin body ...)
(my-cond clauses ...)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment