[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: macros vs. blocks
--- Bruce Lewis <brlewis@alum.mit.edu> wrote:
> A simple example that does #2 and #3 together is
> BRL's inputs syntax.
>
> (inputs foo bar baz)
>
> is equivalent to CGI.pm's
> foo=param('foo');
> bar=param('bar');
> baz=param('baz');
Interesting. I have a similar macro that is a bit
more verbose and a bit more powerful. It's definition
is:
(let-bindings bindings
((name [mapping]) ...))
bindings is an alist of strings, representing form
parameters
name is the name of the variable and it's form
binding as in the inputs macro
mapping is an optional mapping that transforms the
value specified in the bindings. mapping is
string
| (list-of (cons (union string symbol) any))
| string -> any
if mapping is a string, it is the default value
bound to name if no value is given in the
bindings.
if mapping is an alist the value is that
associated with the string value of the
binding.
the symbol default is interpreted specially in
the obvious way
if mapping is a function the result is bound to
name
It seems complicated in prose. Code should help:
(define bindings '(("a" "foo") ("b" "2"))
(let-bindings bindings
((c "cee")
(b (lambda (str) (string->number str)))
(a '(("foo" foo) (default missing))))
(list a b c))
evaluates to
('foo 2 "cee")
I present this as another good example of what can be
done with macros. The equivalent in, say, OO style is
rather more tedious.
Noel
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com