[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
    (name "Grant Rettke")
    (address "1024 Bit St.")
      (name "LyceeSoft")
      (title "Head Taste Tester")
       "Taste Lycees"
       "Peel Lycees"
       "Observe Lycees"))
      (name "PearSoft")
      (title "Head Pear Tester")
       "Taste Pears"
       "Peel Pears"
       "Observe Pears")))))

(define parse
  (λ (res)
    (match res
      (('resume args ...)
         (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 ...)
         (printf "~a Experience~n" type)
         (map parse args)))
        ('name name)
        ('title title)
        ('responsibilities args ...))
         (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.