Racket macro examples
Racket 매크로 예제
#lang racket
(define-syntax-rule (def x ...) (define x ...))
(define-syntax-rule (fn x ...) (lambda x ...))
(define-syntax-rule (++ x) (set! x (add1 x)))
(define-syntax-rule (while test body ...)
(let loop ()
(when test body ... (loop))))
(displayln ((fn (x y) (+ x y)) 1 2))
(def x 0)
(++ x)
(displayln x)
(while (< x 10)
(displayln x)
(++ x))
'Programming' 카테고리의 다른 글
Revenge of the Nerds (0) | 2012.09.27 |
---|---|
Small and Fast (0) | 2012.09.27 |
7 lines of code, 3 minutes: Implement a programming language from scratch (0) | 2012.09.25 |
LispyScript (0) | 2012.09.24 |
Linking newLISP source and executable (0) | 2012.09.24 |