[plt-scheme] Macros and Matching

From: Paulo J. Matos (pocm at soton.ac.uk)
Date: Fri Jul 13 06:43:30 EDT 2007

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

(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) ...)))
             #, at parts))]))

  (machine test
    (a integer 0)
    (b boolean false))
    (=> 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?

Paulo Jorge Matos - pocm at soton.ac.uk
PhD Student @ ECS
University of Southampton, UK

Posted on the users mailing list.