[honu] then is optional in "if". allow multiple sequences in for. add for/fold

This commit is contained in:
Jon Rafkind 2012-01-19 18:21:48 -07:00
parent bc30a94c72
commit a1869fa2f1
4 changed files with 35 additions and 13 deletions

View File

@ -36,6 +36,7 @@
[honu-var var]
[honu-val val]
[honu-for for]
[honu-fold fold]
[honu-to to]
[honu-if if]
[honu-quote quote]

View File

@ -61,7 +61,7 @@
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
#:literals (else honu-then)
[(_ condition:honu-expression honu-then true:honu-expression else false:honu-expression . rest)
[(_ condition:honu-expression (~optional honu-then) true:honu-expression (~optional else) false:honu-expression . rest)
(values
#'(%racket (if condition.result true.result false.result))
#'rest
@ -413,18 +413,23 @@
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
#:literals (honu-equal honu-in)
#;
[(_ iterator:id honu-equal start:honu-expression honu-to end:honu-expression
[(_ (~seq iterator:id honu-in stuff:honu-expression (~optional honu-comma)) ...
honu-do body:honu-expression . rest)
(values
#'(%racket (for/list ([iterator (in-range start.result
end.result)])
body.result))
#'rest
#t)]
[(_ iterator:id honu-in stuff:honu-expression
honu-do body:honu-expression . rest)
(values #'(%racket (for/list ([iterator stuff.result])
(values #'(%racket (for ([iterator stuff.result] ...)
body.result))
#'rest
#t)])))
(provide honu-fold)
(define-honu-syntax honu-fold
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
#:literals (honu-equal honu-in)
[(_ (~seq init:id honu-equal init-expression:honu-expression (~optional honu-comma)) ...
(~seq iterator:id honu-in stuff:honu-expression (~optional honu-comma)) ...
honu-do body:honu-expression . rest)
(values #'(%racket (for/fold ([init init-expression.result] ...)
([iterator stuff.result] ...)
body.result))
#'rest
#t)])))

View File

@ -354,7 +354,7 @@
stream)]
[else
(define-splicing-syntax-class no-left
[pattern (~seq) #:when (not current)])
[pattern (~seq) #:when (and (= precedence 0) (not current))])
(syntax-parse #'(head rest ...) #:literal-sets (cruft)
[((semicolon more ...) . rest)
#;

View File

@ -11,3 +11,19 @@ for x in 1 to 10 do {
for x in [1, 2, 3] do {
printf("x ~a\n", x);
}
for x in 0 to 3,
y in 2 to 5 do {
printf("x ~a y ~a\n", x, y)
}
fold x = [],
z in 0 to 5 do {
z :: x
}
fold x = [],
y = 1,
z in 1 to 5 do {
values(z :: x, y * z)
}