Re: Why is this macro misbehaving?
- From: Zach Beane <xach@xxxxxxxx>
- Date: 26 Oct 2006 15:49:59 -0400
"jmckitrick" <j_mckitrick@xxxxxxxxx> writes:
I'd like to take a string like this: "1/2/3"
and bind it like this:
(let ((item "1") (arg1 "2") (arg2 "3"))
body)
Here's the macro:
(defmacro with-url ((&rest vars) seq &body body)
(let ((subseqs (split-sequence #\/ seq :remove-empty-subseqs t)))
`(let ,(loop
for var in vars
for subseq in subseqs collect
`(,var ,subseq))
,@body)))
The splitting must be done at runtime, not macroexpansion time.
(with-url (item arg1 arg2) (request-unhandled-part request)
(format t "arg1: ~A~%" arg1))
In this call, your macro gets the list (REQUEST-UNHANDLED-PART
REQUEST) as the SEQ argument. Trying to use split-sequence on it will
not work.
You need to move the splitting work into runtime; that's when the
value (rather than the form that produces the value) is available.
At that point, though, there's very little to be gained over simply
using DESTRUCTURING-BIND.
Zach
.
- Follow-Ups:
- Re: Why is this macro misbehaving?
- From: jmckitrick
- Re: Why is this macro misbehaving?
- References:
- Why is this macro misbehaving?
- From: jmckitrick
- Why is this macro misbehaving?
- Prev by Date: Re: Someone explain (Mc)Clim to me as if I were 5 years old
- Next by Date: Re: Someone explain (Mc)Clim to me as if I were 5 years old
- Previous by thread: Why is this macro misbehaving?
- Next by thread: Re: Why is this macro misbehaving?
- Index(es):
Relevant Pages
|
Loading