[plt-scheme] The role of macros in solving this little problem

From: Grant Rettke (grettke at acm.org)
Date: Sat Sep 1 19:12:34 EDT 2007

On 8/31/07, Noel Welsh <noelwelsh at gmail.com> wrote:
> There is no need to use macros here.  You could make this a list of
> symbols and string, and use match to process it.  You could make this
> a combinator library that constructs structures and use match. The
> second is a fancy-schmancy version of the first.

Something like this?

(require (lib "match.ss"))

(define gres
  '(resume
    (name "Grant Rettke")
    (address "1024 Bit St.")
    (experience
     "Professional"
     (work-entry
      (name "LyceeSoft")
      (title "Head Taste Tester")
      (responsibilities
       "Taste Lycees"
       "Peel Lycees"
       "Observe Lycees"))
     (work-entry
      (name "PearSoft")
      (title "Head Pear Tester")
      (responsibilities
       "Taste Pears"
       "Peel Pears"
       "Observe Pears")))))

(define parse
  (λ (res)
    (match res
      (('resume args ...)
       (begin
         (printf "Begin resume~n")
         (map parse args)
         (printf "End resume~n")))
      (('name name)
       (printf "Name: ~a~n" name))
      (('address address)
       (printf "Address: ~a~n" address))
      (('experience type args ...)
       (begin
         (printf "~a Experience~n" type)
         (map parse args)))
      (('work-entry
        ('name name)
        ('title title)
        ('responsibilities args ...))
       (begin
         (printf "Company: ~a~n" name)
         (printf "Title: ~a~n" title)
         (map (λ (arg) (printf "  * ~a~n" arg)) args))))))

(parse gres)

Posted on the users mailing list.