标签:使用 ar for sp on c line ef r
#lang racket (define-syntax for (syntax-rules (in : as) ((_ (i : list) body ...) (map (lambda (i) body ...) list)) ((_ i in list body ...) (map (lambda (i) body ...) list)) ((_ list as i body ...) (map (lambda (i) body ...) list)) ((_ (i from to) b1 ...) (let loop [(i from)] (when (< i to) b1 ... (loop (+ 1 i))))) ((_ (i from to step) b1 ...) (let loop [(i from)] (when (< i to) b1 ... (loop (+ i step))))))) (for (i : ‘(0 1 2 3 4 5)) (print i) (newline)) (newline) (for i in ‘(0 1 2 3 4 5) (print i) (newline)) (newline) (for ‘(0 1 2 3 4 5) as i (print i) (newline)) (newline) (for (i 0 5) (print i) (newline)) (newline) (for (i 0 10 2) (print i) (newline))
>>
欢迎使用 DrRacket, 版本 6.0.1 [3m].
语言: racket [自定义]; memory limit: 500 MB.
0
1
2
3
4
5
‘(#<void> #<void> #<void> #<void> #<void> #<void>)
0
1
2
3
4
5
‘(#<void> #<void> #<void> #<void> #<void> #<void>)
0
1
2
3
4
5
‘(#<void> #<void> #<void> #<void> #<void> #<void>)
0
1
2
3
4
0
2
4
6
8
>
标签:使用 ar for sp on c line ef r
原文地址:http://my.oschina.net/firebroo/blog/318513