[plt-scheme] Re: Macros and Matching
Just found why doesn't work. From R5RS:
"The keyword at the beginning of the pattern in a <syntax rule> is not
involved in the matching and is not considered a pattern variable or
literal identifier."
Any ideas on the best way to solve this?
Cheers,
Paulo Matos
On 13/07/07, Paulo J. Matos <pocm at soton.ac.uk> wrote:
> Hi all,
>
> I have a macro which defines a specification language on top of scheme
> and sometimes it is behaving in unexpected ways (to me). Here's a
> sample:
>
> (module test mzscheme
>
> (define-syntax (machine stx)
> (syntax-case stx ()
> [(_ mname sexps ...)
> (identifier? #'mname) ; fender
> (let* ([sections (syntax->list #'(sexps ...))]
> [parts (map (syntax-rules (variables properties)
> ((variables (name type value) ...)
> (begin (printf "Var ~a : ~a -> ~a~n"
> 'name 'type 'value) ...))
> ((properties formula ...)
> (begin (printf "Prop ~a~n" 'formula) ...)))
> sections)])
> #`(begin
> #, at parts))]))
>
> (machine test
> (variables
> (a integer 0)
> (b boolean false))
> (properties
> (=> a b))))
>
> The output is:
> Var a : integer -> 0
> Var b : boolean -> false
> Var => : a -> b
>
> Obviously the last line is wrong. Why is (=> a b) being matched to a
> variable? I understand that it is matching => to name, a to type and b
> to value but it is inside the properties section so should definitely
> not be matched to a variable. What's the problem with this?
>
> Cheers,
> --
> Paulo Jorge Matos - pocm at soton.ac.uk
> http://www.personal.soton.ac.uk/pocm
> PhD Student @ ECS
> University of Southampton, UK
>
--
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK