William James
6/5/2015 3:59:00 PM
Dr. Edmund Weitz wrote:
> > (defmacro foo (a)
> > `(list ,@(loop for (s nil c) in a
> > collecting `((:option :value ,s)
> > ,c))))
> > The following usage of it works as expected:
> >
> > (foo (("a" :a "A") ("b" :b "B") ("c" :c "C")))
> >
> > But suppose I'll define some variable, because I'm going to
> > use the same value several times:
> >
> > (defvar *bar* '(("a" :a "A") ("b" :b "B") ("c" :c "C")))
> >
> > And then try to call FOO the following way:
> >
> > (foo *bar*)
> >
> > This doesn't work. I can surround A inside FOO with EVAL. But
> > I've read somewhere that this would be a bad style. I think
> > some technique exists for such things, please let me know.
> >
.....
> it looks to me as if you want to transform a list and I wonder why you
> need a macro at all. Wouldn't a function like this be sufficient?
>
> * (defun foo (a)
> (loop for (s nil c) in a
> collecting `((:option :value ,s)
> ,c)))
> FOO
> * (foo '(("a" :a "A") ("b" :b "B") ("c" :c "C")))
> (((:OPTION :VALUE "a") "A") ((:OPTION :VALUE "b") "B")
> ((:OPTION :VALUE "c") "C"))
Gauche Scheme:
(define (foo input)
(map
(^x `((:option :value ,(car x)) ,(last x)))
input))
(foo '(("a" :a "A") ("b" :b "B") ("c" :c "C")))
===>
(((:option :value "a") "A")
((:option :value "b") "B")
((:option :value "c") "C"))
--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot