summaryrefslogtreecommitdiffhomepage
path: root/racket.html.markdown
diff options
context:
space:
mode:
authorManu <manu.delab@gmail.com>2013-07-16 10:51:38 +1200
committerManu <manu.delab@gmail.com>2013-07-16 10:51:38 +1200
commit6ff708a040868e99936e73edd18575181bd2e367 (patch)
tree80f0500c3d130c770f6ed3e25fc890735b69b9d1 /racket.html.markdown
parent13604e79328b211e5e3bd7f3123be696cd8d3096 (diff)
replace unless macro by a while macro
Diffstat (limited to 'racket.html.markdown')
-rw-r--r--racket.html.markdown14
1 files changed, 11 insertions, 3 deletions
diff --git a/racket.html.markdown b/racket.html.markdown
index 707919dd..84dc2ada 100644
--- a/racket.html.markdown
+++ b/racket.html.markdown
@@ -404,10 +404,18 @@ vec ; => #(1 2 3 4)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Macros let you extend the syntax of the language
-(define-syntax-rule (unless test then else)
- (if test else then))
-(unless (even? 10) "odd" "even") ; => "even"
+; Let's add a while loop
+(define-syntax-rule (while condition body ...)
+ (let loop ()
+ (when condition
+ body ...
+ (loop))))
+
+(let ([i 0])
+ (while (< i 10)
+ (displayln i)
+ (set! i (add1 i))))
; Macros are hygienic, you cannot clobber existing variables!
(define-syntax-rule (swap x y)