Appropriate case for a macro?
- From: Brian Adkins <lojicdotcom@xxxxxxxxx>
- Date: Mon, 31 Mar 2008 09:33:12 -0700 (PDT)
I program primarily in Ruby and have been trying to find time to learn
Lisp. One of the things that attracts me to Lisp is the macro
facility. Consider the following pattern:
if a_long_expression > value
foo(a_long_expression)
bar(a_long_expression)
else
baz(a_long_expression)
end
This can be made more concise via an assignment:
if (x = a_long_expression) > value
foo(x)
bar(x)
else
baz(x)
end
However, this seems like a pragmatic hack since a new variable is
introduced simply for conciseness. Would you consider this an
appropriate case for a macro in Common Lisp?
Perhaps used as follows:
(my-if (> a-long-expression value)
(progn
(foo lhs)
(bar lhs))
(baz lhs))
where a-long-expression has been replaced by lhs
.
- Follow-Ups:
- Re: Appropriate case for a macro?
- From: Chris Riesbeck
- Re: Appropriate case for a macro?
- From: Brian
- Re: Appropriate case for a macro?
- Prev by Date: Re: Two questions about prog2
- Next by Date: Re: Listing slots in CLOS
- Previous by thread: Two questions about eq
- Next by thread: Re: Appropriate case for a macro?
- Index(es):
Relevant Pages
|