Created
December 9, 2015 19:57
-
-
Save Glorp/8c0cd81065afe3ce28a0 to your computer and use it in GitHub Desktop.
This file contains 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
#lang racket | |
(define-syntax-rule (run x) | |
(begin (printf "> ~a~n" 'x) | |
(printf "~a~n" x))) | |
(define-syntax-rule (baklengs a b c d) | |
(d c b a)) | |
(run (baklengs 2 1 #f if)) | |
(define-syntax (foo stx) | |
(syntax-case stx (bar) | |
[(_ bar a) #'a] | |
[(_ a b) #''(b a)])) | |
(run (foo bar 1)) | |
(run (foo hest marsvin)) | |
(define-syntax aiif | |
(syntax-rules () | |
[(_ it condition then else) | |
(let ([it condition]) | |
(if it then else))])) | |
(define (ganger n) (* n n)) | |
(run (aiif eet (ganger 3) (* eet eet) eet)) | |
(run (aiif eet #f (* eet eet) eet)) | |
(define-syntax (aif stx) | |
(with-syntax ([it (datum->syntax stx 'it stx)]) | |
(syntax-case stx (aiif) | |
[(_ condition then else) | |
#'(aiif it condition then else)] | |
[(_ condition then else . stuff) | |
(raise-syntax-error #f "too much stuff:" stx #'stuff)]))) | |
(run (aif (ganger 3) (* it it) it)) | |
; ikke-kommenter linjen under for syntaks-feil | |
;(run (aif (ganger 3) (* it it) it asd qwe)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment