Created
August 6, 2019 21:07
-
-
Save ruliana/b0d1eed0faed9a414d1a06d40e89a2e6 to your computer and use it in GitHub Desktop.
Scheme "power-let" exploring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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