From bef2f188b3e82c6fc38215335e117c655f43e180 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Mon, 21 Nov 2011 12:14:32 -0700 Subject: [PATCH] [honu] move when macro to the honu language --- collects/honu/core/main.rkt | 3 +++ collects/honu/core/private/honu2.rkt | 9 +++++++++ collects/honu/core/private/macro2.rkt | 4 +++- collects/honu/main.rkt | 7 +++---- collects/honu/private/common.honu | 7 +++++++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/collects/honu/core/main.rkt b/collects/honu/core/main.rkt index e1d2491b0e..b62186782a 100644 --- a/collects/honu/core/main.rkt +++ b/collects/honu/core/main.rkt @@ -14,12 +14,15 @@ (provide (for-meta meta-level (rename-out [parse:honu-expression expression] [parse:honu-identifier identifier] + [racket:else else] + [racket:void void] [honu-function function] [honu-var var] [honu-equal =] [honu--> %arrow] [honu-class class] [honu-require require] + [honu-provide provide] [honu-new new] [honu-while while] [honu-macro macro] diff --git a/collects/honu/core/private/honu2.rkt b/collects/honu/core/private/honu2.rkt index dccd5a0354..240b9ebc35 100644 --- a/collects/honu/core/private/honu2.rkt +++ b/collects/honu/core/private/honu2.rkt @@ -260,6 +260,15 @@ #'rest #f)]))) +(provide honu-provide) +(define-honu-syntax honu-provide + (lambda (code context) + (syntax-parse code + [(_ name:id ...) + (values #'(%racket (provide name ...)) + #'() + #f)]))) + (provide honu-with-input-from-file) (define-honu-syntax honu-with-input-from-file (lambda (code context) diff --git a/collects/honu/core/private/macro2.rkt b/collects/honu/core/private/macro2.rkt index 66e249a316..0729ef095e 100644 --- a/collects/honu/core/private/macro2.rkt +++ b/collects/honu/core/private/macro2.rkt @@ -59,7 +59,7 @@ (lambda (code context) (debug "Macroize ~a\n" code) (syntax-parse code #:literal-sets (cruft) - [(_ name literals (#%braces pattern ...) (#%braces action ...) . rest) + [(_ name (#%parens literal ...) (#%braces pattern ...) (#%braces action ...) . rest) (debug "Pattern is ~a\n" #'(pattern ...)) (debug 2 "Pattern variables ~a\n" (find-pattern-variables #'(pattern ...))) (values @@ -69,7 +69,9 @@ (find-pattern-variables #'(pattern ...))]) #'(%racket (define-honu-syntax name (lambda (stx context-name) + (define-literal-set local-literals (literal ...)) (syntax-parse stx + #:literal-sets (cruft local-literals) [(_ syntax-parse-pattern ... . more) (values ;; if the pattern is x:expression then x_result will diff --git a/collects/honu/main.rkt b/collects/honu/main.rkt index 7b5e8c25d6..df023653dc 100644 --- a/collects/honu/main.rkt +++ b/collects/honu/main.rkt @@ -12,24 +12,23 @@ (provide-module "core/main.rkt" "private/common.rkt" + "private/common.honu" ;;"private/struct.honu" ;;"private/function.honu" - ;;"private/common.honu" ) -(provide sqr sqrt sin max else +(racket:provide sqr sqrt sin max number? symbol? null null? length substring - void format integer cos sin random values - (rename-out [honu-cond cond] + (racket:rename-out [honu-cond cond] [null empty] [current-inexact-milliseconds currentMilliseconds] [string-length string_length] diff --git a/collects/honu/private/common.honu b/collects/honu/private/common.honu index ada454d5e1..9e44088e45 100644 --- a/collects/honu/private/common.honu +++ b/collects/honu/private/common.honu @@ -1,5 +1,11 @@ #lang honu/core +provide when; +macro when (then){ condition:expression then body:expression }{ + syntax(if condition then body else { void() }) +} + +/* require (forSyntax "with.honu"); require (forSyntax "function.honu"); require (forSyntax "patterns.honu"); @@ -36,3 +42,4 @@ macro condition (){ _ clause:condition_clause rest ... ;} } ); } { _ ; } { syntax(1;); } +*/