Skip to content

Instantly share code, notes, and snippets.

@ruliana
Created August 9, 2019 23:04
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 ruliana/e8f8181fda6d8866be632a0fd09b219f to your computer and use it in GitHub Desktop.
Save ruliana/e8f8181fda6d8866be632a0fd09b219f to your computer and use it in GitHub Desktop.
Fighting scheme macros
(define empty? null?)
(define empty '())
(define first car)
(define rest cdr)
(define (split2 item lst)
(let loop ([remaining lst]
[left empty])
(cond [(empty? remaining) (values (reverse left) empty)]
[(equal? item (first remaining)) (values (reverse left) (rest remaining))]
[else (loop (rest remaining) (cons (first remaining) left))])))
(define (reverse-thing stx)
stx)
(define-syntax (power-let stx)
(syntax-case stx ()
[(_ body0 body* ...)
(with-syntax ([new-body (reverse-thing #'body0)])
#'(let [new-body] body* ...))]))
;(power-let (1 a) (printf "~s\n" a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment