Skip to content

Instantly share code, notes, and snippets.

@obriencj
Created July 20, 2017 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obriencj/e753e35acf4c52054b4d976460eda481 to your computer and use it in GitHub Desktop.
Save obriencj/e753e35acf4c52054b4d976460eda481 to your computer and use it in GitHub Desktop.
sibilant macros and quasiquote
maybe:python-sibilant siege$ sibilant sample.lspy
True is True
False is False
None is False
nil is False
True is True
100 is True
False is False
-100 is True
(1 will you 8 flake tacos_1 tacos_2 tacos_3 tacos_4 tacos_5 tacos_2 tacos_3 tacos_4 tacos_5)
(defmacro if (condition true_body . &false_body)
(make-list 'cond
(make-list condition true_body)
(make-list 'else
(cond (&false_body (car &false_body))
(else 'False)))))
(defmacro when (condition . &body)
(make-list 'cond
(make-list condition (cons 'begin &body))
(make-list 'else 'False)))
(defmacro unless (condition . &body)
(make-list 'cond
(make-list condition 'False)
(make-list 'else (cons 'begin &body))))
(defmacro attempt (value)
(make-list 'let (make-list (make-list 'v value))
(make-list 'print 'v "is"
(make-list 'if 'v "True" "False"))))
(if True
(begin
(attempt True)
(attempt False)
(attempt None)
(attempt nil)
(attempt 1)
(attempt 100)
(attempt 0)
(attempt -100)))
(define tacos '(tacos_1 tacos_2 tacos_3 tacos_4 tacos_5))
(define val
`(1 will you ,(if True 8 9) flake ,@tacos ,@(cdr tacos)))
(print val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment