[plt-scheme] The role of macros in solving this little problem
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)