Skip to content

Instantly share code, notes, and snippets.

@ruliana
Created August 6, 2019 21:07
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/b0d1eed0faed9a414d1a06d40e89a2e6 to your computer and use it in GitHub Desktop.
Save ruliana/b0d1eed0faed9a414d1a06d40e89a2e6 to your computer and use it in GitHub Desktop.
Scheme "power-let" exploring
(trace-define-syntax power-let
(syntax-rules (<-)
[(_ (v <- expr) rest ...) (let [(v expr)] (power-let rest ...))]
[(_ body0 body* ...) (begin body0 body* ...)]))
(define-syntax def
(syntax-rules ()
((_ (name args ...) body ...)
(define (name args ...)
(power-let body ...)))))
(def (test1 a b) (+ a b))
(printf "~s\n" (test1 1 2))
(power-let (a <- 1)
(b <- 2)
(printf "~s ~s\n" a b))
(printf "\n")
(def (test2 a b)
(c <- (+ a b))
(printf "~s\n" c)
(list a b c))
(printf "~s\n" (test2 1 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment