[honu] make "then" keyword required for if again. start to add more loop types to for

This commit is contained in:
Jon Rafkind 2012-01-23 16:38:16 -07:00
parent a1869fa2f1
commit 2af9100a5d
5 changed files with 27 additions and 9 deletions

View File

@ -28,7 +28,8 @@
[honu-new new]
[honu-while while]
[honu-macro macro]
[honu-with-input-from-file with_input_from_file]
[racket:read-line readLine]
[honu-with-input-from-file withInputFromFile]
[define-make-honu-operator operator]
[honu-match match]
[honu-with with]
@ -70,6 +71,7 @@
[literal:honu-comma %comma]
[literal:honu-comma %comma]
[literal:honu-<- <-]
[literal:honu-in-lines inLines]
[literal:#%brackets #%brackets]
[literal:#%braces #%braces]
[literal:#%parens #%parens])

View File

@ -2,4 +2,7 @@
(provide do-lookup)
(define (do-lookup data slice)
(list-ref data slice))
(cond
[(list? data) (list-ref data slice)]
[(vector? data) (vector-ref data slice)]
[else (error 'lookup "don't know how to lookup" data)]))

View File

@ -10,6 +10,7 @@
(only-in "literals.rkt"
honu-then
honu-in
honu-in-lines
honu-prefix
semicolon
honu-comma
@ -61,7 +62,7 @@
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
#:literals (else honu-then)
[(_ condition:honu-expression (~optional honu-then) true:honu-expression (~optional else) false:honu-expression . rest)
[(_ condition:honu-expression honu-then true:honu-expression (~optional else) false:honu-expression . rest)
(values
#'(%racket (if condition.result true.result false.result))
#'rest
@ -297,8 +298,9 @@
(define-honu-syntax honu-with-input-from-file
(lambda (code context)
(syntax-parse code #:literal-sets (cruft)
[(_ (#%parens name:id) something:honu-expression . rest)
(define with #'(%racket (with-input-from-file name (lambda () something.result))))
[(_ file:honu-expression something:honu-expression . rest)
(define with #'(%racket (with-input-from-file file.result
(lambda () something.result))))
(values
with
#'rest
@ -423,13 +425,21 @@
(provide honu-fold)
(define-honu-syntax honu-fold
(lambda (code context)
(define-splicing-syntax-class sequence-expression
#:literals (honu-in honu-in-lines)
[pattern (~seq iterator:id honu-in stuff:honu-expression)
#:with variable #'iterator
#:with expression #'stuff.result]
[pattern (~seq iterator:id honu-in-lines)
#:with variable #'iterator
#:with expression #'(in-lines)])
(syntax-parse code #:literal-sets (cruft)
#:literals (honu-equal honu-in)
#:literals (honu-equal)
[(_ (~seq init:id honu-equal init-expression:honu-expression (~optional honu-comma)) ...
(~seq iterator:id honu-in stuff:honu-expression (~optional honu-comma)) ...
(~seq sequence:sequence-expression (~optional honu-comma)) ...
honu-do body:honu-expression . rest)
(values #'(%racket (for/fold ([init init-expression.result] ...)
([iterator stuff.result] ...)
([sequence.variable sequence.expression] ...)
body.result))
#'rest
#t)])))

View File

@ -31,6 +31,8 @@
honu-for-syntax
honu-for-template
honu-prefix
;; FIXME: in-lines should probably not be here
honu-in-lines
%racket)
(define-syntax-rule (define-literal+set set literal ...)

View File

@ -17,7 +17,7 @@
;;"private/function.honu"
)
(racket:provide sqr sqrt sin max
(racket:provide sqr sqrt sin max min
number? symbol?
null
null?
@ -36,6 +36,7 @@
[current-inexact-milliseconds currentMilliseconds]
[string-length string_length]
[string-append string_append]
[current-command-line-arguments commandLineArguments]
[racket:find-files find_files]
[racket:empty? empty?]
[regexp-match regexp_match]