From b74ad87160697a8cca92401d1d048ae307b20fd0 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Wed, 1 Feb 2012 14:45:30 -0700 Subject: [PATCH] [honu] wrap the condition of when expression inside parentheses. instantiate literal sets at the proper phase for honu macros --- collects/honu/core/private/honu2.rkt | 2 +- collects/honu/core/private/macro2.rkt | 19 +++++++++++-------- collects/honu/private/common.honu | 4 ++-- collects/tests/honu/check.rkt | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/collects/honu/core/private/honu2.rkt b/collects/honu/core/private/honu2.rkt index 33f3605ca6..c03c06e7ac 100644 --- a/collects/honu/core/private/honu2.rkt +++ b/collects/honu/core/private/honu2.rkt @@ -68,7 +68,7 @@ (lambda (code context) (syntax-parse code #:literal-sets (cruft) #:literals (else honu-then) - [(_ condition:honu-expression honu-then true:honu-expression (~optional else) false:honu-expression . rest) + [(_ (#%parens condition:honu-expression) true:honu-expression (~optional else) false:honu-expression . rest) (values #'(%racket (if condition.result true.result false.result)) #'rest diff --git a/collects/honu/core/private/macro2.rkt b/collects/honu/core/private/macro2.rkt index eb8bc1bbb2..a4e9ce98a0 100644 --- a/collects/honu/core/private/macro2.rkt +++ b/collects/honu/core/private/macro2.rkt @@ -22,23 +22,25 @@ (define-splicing-syntax-class pattern-type #:literal-sets (cruft) [pattern (~seq name colon class) - #:with result #'(~var name class #:attr-name-separator "_")] - [pattern x #:with result #'x]) + #:with (result ...) #'((~var name class #:attr-name-separator "_"))] + [pattern (x:pattern-type ...) #:with (result ...) #'((x.result ... ...))] + [pattern x #:with (result ...) #'(x)]) (syntax-parse original-pattern [(thing:pattern-type ...) - #'(thing.result ...)])) + #'(thing.result ... ...)])) (define-for-syntax (find-pattern-variables original-pattern) (define-splicing-syntax-class pattern-type #:literal-sets (cruft) [pattern (~seq name colon class) ;; we know the output of syntactic classes will end with _result - #:with result (with-syntax ([name.result (format-id #'name "~a_result" #'name)]) - #'(name name.result))] - [pattern x #:with result #f]) + #:with (result ...) (with-syntax ([name.result (format-id #'name "~a_result" #'name)]) + #'((name name.result)))] + [pattern (x:pattern-type ...) #:with (result ...) #'(x.result ... ...)] + [pattern x #:with (result ...) #'()]) (syntax-parse original-pattern [(thing:pattern-type ...) - (filter (lambda (x) (syntax-e x)) (syntax->list #'(thing.result ...)))])) + (filter (lambda (x) (syntax-e x)) (syntax->list #'(thing.result ... ...)))])) (begin-for-syntax (define-syntax (parse-stuff stx) @@ -63,7 +65,8 @@ (lambda (stx context-name) (define-literal-set local-literals (literal ...)) (syntax-parse stx - #:literal-sets (cruft local-literals) + #:literal-sets ([cruft #:at name] + [local-literals #:at name]) [(_ syntax-parse-pattern ... . more) (values ;; if the pattern is x:expression then x_result will diff --git a/collects/honu/private/common.honu b/collects/honu/private/common.honu index 9e44088e45..0a62ee1579 100644 --- a/collects/honu/private/common.honu +++ b/collects/honu/private/common.honu @@ -1,8 +1,8 @@ #lang honu/core provide when; -macro when (then){ condition:expression then body:expression }{ - syntax(if condition then body else { void() }) +macro when (){ (condition:expression) body:expression }{ + syntax(if (condition) body else { }) } /* diff --git a/collects/tests/honu/check.rkt b/collects/tests/honu/check.rkt index 99040a0d05..7ee0fc00fd 100644 --- a/collects/tests/honu/check.rkt +++ b/collects/tests/honu/check.rkt @@ -104,7 +104,7 @@ (test "if" @input{ - if 2 > 1 then + if (2 > 1) 1 else 0