From 2af9100a5d7e8a979cea0de6920ff83319d75548 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Mon, 23 Jan 2012 16:38:16 -0700 Subject: [PATCH] [honu] make "then" keyword required for if again. start to add more loop types to for --- collects/honu/core/main.rkt | 4 +++- collects/honu/core/private/extra.rkt | 5 ++++- collects/honu/core/private/honu2.rkt | 22 ++++++++++++++++------ collects/honu/core/private/literals.rkt | 2 ++ collects/honu/main.rkt | 3 ++- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/collects/honu/core/main.rkt b/collects/honu/core/main.rkt index b3d5136dc2..bbef07961c 100644 --- a/collects/honu/core/main.rkt +++ b/collects/honu/core/main.rkt @@ -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]) diff --git a/collects/honu/core/private/extra.rkt b/collects/honu/core/private/extra.rkt index 1c6824abc3..1dfe234e04 100644 --- a/collects/honu/core/private/extra.rkt +++ b/collects/honu/core/private/extra.rkt @@ -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)])) diff --git a/collects/honu/core/private/honu2.rkt b/collects/honu/core/private/honu2.rkt index 979e2253f4..589a69f9f6 100644 --- a/collects/honu/core/private/honu2.rkt +++ b/collects/honu/core/private/honu2.rkt @@ -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)]))) diff --git a/collects/honu/core/private/literals.rkt b/collects/honu/core/private/literals.rkt index 83c54df9d8..e559280a3f 100644 --- a/collects/honu/core/private/literals.rkt +++ b/collects/honu/core/private/literals.rkt @@ -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 ...) diff --git a/collects/honu/main.rkt b/collects/honu/main.rkt index 630e12c4a4..eb8f744220 100644 --- a/collects/honu/main.rkt +++ b/collects/honu/main.rkt @@ -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]