In PCL, chapter 8 - "Macros: Defining Your Own", Peter Seibel presents
the macro-writing macro ONCE-ONLY: "Another classic macro-writing
macro is once-only, which is used to generate code that evaluates
certain macro arguments once only and in a particular order. "
My doubt is, given that the pattern ONCE-ONLY abstracts is so common,
isn't there an equivalent defined in the standard? Or does everybody
use Peter Seibel's ONCE-ONLY?
|
|
0
|
|
|
|
Reply
|
o.simon (7)
|
4/6/2011 4:05:36 AM |
|
In article
<abb9b34e-0694-4f7d-8953-b71d6159a016@34g2000pru.googlegroups.com>,
Simon Ortiz <o.simon@gmail.com> wrote:
> My doubt is, given that the pattern ONCE-ONLY abstracts is so common,
> isn't there an equivalent defined in the standard? Or does everybody
> use Peter Seibel's ONCE-ONLY?
No, there's no standard macro for this. I don't recall it even coming
up for discussion during standardization.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
0
|
|
|
|
Reply
|
barmar (5626)
|
4/6/2011 4:15:41 AM
|
|
Barry Margolin <barmar@alum.mit.edu> wrote:
+---------------
| Simon Ortiz <o.simon@gmail.com> wrote:
| > My doubt is, given that the pattern ONCE-ONLY abstracts is so common,
| > isn't there an equivalent defined in the standard? Or does everybody
| > use Peter Seibel's ONCE-ONLY?
|
| No, there's no standard macro for this. I don't recall it even
| coming up for discussion during standardization.
+---------------
Though there are certainly variants which predate Peter's, e.g.,
there's a ONCE-ONLY macro defined in CMUCL ["code/extensions.lisp",
line 297 in version 19f] with a slightly different API than Peter's:
"Once-Only ({(Var Value-Expression)}*) Form*
Create a Let* which evaluates each Value-Expression, binding a temporary
variable to the result, and wrapping the Let* around the result of the
evaluation of Body. Within the body, each Var is bound to the corresponding
temporary variable."
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw3.org/>
San Mateo, CA 94403
|
|
0
|
|
|
|
Reply
|
rpw3 (2294)
|
4/6/2011 9:33:41 AM
|
|
Ok, thanks for the explanation!
|
|
0
|
|
|
|
Reply
|
o.simon (7)
|
4/6/2011 9:39:17 AM
|
|
SO> My doubt is, given that the pattern ONCE-ONLY abstracts is so common,
SO> isn't there an equivalent defined in the standard?
It is just a conveniece function and is not necessary. There are other ways
to do it, e.g. Doug Hoyte describes macro similar to once-only which is even
more conventient but funky.
SO> Or does everybody use Peter Seibel's ONCE-ONLY?
I think everybody should use Alexandria library:
http://common-lisp.net/project/alexandria/
It is, basically, a collection of commonly used tools and utilities which
are widely used to the point where people think "they should be in the
standard".
Actually there is a lot of utility libraries
(http://www.cliki.net/utilities) which often provide quite similar
macros/functions and that proves the fact that "they should be in the
standard".
Alexandria is meant to stop this madness and provide a common base so people
will stop doing this over and over and over again.
I'd say ONCE-ONLY is not the most missed macro/function.
My personal list (alexandria nomenclature):
1. IF-LET/WHEN-LET
2. ASSOC-VALUE replaces the ugly (CAR (ASSOC ..)) combo
3. ALIST-PLIST/PLIST-ALIST
4. SWITCH
5. STARTS-WITH-SUBSEQ
6. IOTA
7. LASTCAR because 99% of time you write (car (last ...))
8. ENSURE-CONS
I also have a lot of code which looks like:
(or (gethash foo bar)
(setf (gethash foo bar) (compute-value))
I wish Alexandria had macro for it but unfortunately there is no, so I ended
writing my own macro
(get-or-init (gethash foo bar)
(compute-value))
Alexandria has function ensure-gethash key hash-table &optional default
but the problem is that default is always evaluated, even if it is not used.
This sucks.
|
|
0
|
|
|
|
Reply
|
udodenko (1040)
|
4/6/2011 10:37:31 AM
|
|
"Captain Obvious" <udodenko@users.sourceforge.net> writes:
> SO> My doubt is, given that the pattern ONCE-ONLY abstracts is so common,
> SO> isn't there an equivalent defined in the standard?
>
> It is just a conveniece function and is not necessary. There are other
> ways to do it, e.g. Doug Hoyte describes macro similar to once-only
> which is even more conventient but funky.
>
> SO> Or does everybody use Peter Seibel's ONCE-ONLY?
>
> I think everybody should use Alexandria library:
> http://common-lisp.net/project/alexandria/
> It is, basically, a collection of commonly used tools and utilities
> which are widely used to the point where people think "they should be
> in the standard".
>
> Actually there is a lot of utility libraries
> (http://www.cliki.net/utilities) which often provide quite similar
> macros/functions and that proves the fact that "they should be in the
> standard".
> Alexandria is meant to stop this madness and provide a common base so
> people will stop doing this over and over and over again.
>
> I'd say ONCE-ONLY is not the most missed macro/function.
Foremost when you consider the pros and cons:
(defmacro mm (x)
(let ((vx (gensym)))
`(let ((,vx ,x))
(stuff ,vx ,vx))))
Pro: simple to write
no overhead
simple to read (needs to know only CL),
no dependencies
Con: you need to know what you're doing and why you need it, and not
make an error in realisation.
vs.
(asdf:load-op :alexandria)
(use-package :alexandria)
(defmacro mm (x)
(once-only (x)
`(stuff ,x ,x)))
Pro: simple to write
you can be more mindless
Con: has overhead
less simple to read (you now need to know alexandria)
has a dependency
So unless you have a lot of such macros to write, or you have other
needs for a dependency on alexandria (which could occur quite easily),
ONCE-ONLY doesn't seem so needed.
That said, I have (asdf:load-op :alexandria) in my rc files,
along of course with (asdf:load-op :com.informatimago.common-lisp) which
loads cesarum ;-)
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
|
|
0
|
|
|
|
Reply
|
pjb (7647)
|
4/6/2011 10:17:51 PM
|
|
On 06/04/2011 06:05, Simon Ortiz wrote:
> In PCL, chapter 8 - "Macros: Defining Your Own", Peter Seibel presents
> the macro-writing macro ONCE-ONLY: "Another classic macro-writing
> macro is once-only, which is used to generate code that evaluates
> certain macro arguments once only and in a particular order. "
>
> My doubt is, given that the pattern ONCE-ONLY abstracts is so common,
> isn't there an equivalent defined in the standard? Or does everybody
> use Peter Seibel's ONCE-ONLY?
LispWorks has 'rebinding which I like a lot.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
The views expressed are my own, and not those of my employer.
|
|
0
|
|
|
|
Reply
|
pc56 (3896)
|
4/8/2011 8:07:56 PM
|
|
On 2011-04-08 16:07:56 -0400, Pascal Costanza said:
> LispWorks has 'rebinding which I like a lot.
Yes, I use this all the time. It's also available portably as part of arnesi:
<http://common-lisp.net/project/bese/docs/arnesi/html/api/macro_005FIT.BESE.ARNESI_003A_003AREBINDING.html>
warmest
regards,
Ralph
--
Raffael Cavallaro
|
|
0
|
|
|
|
Reply
|
raffaelcavallaro6342 (133)
|
4/8/2011 10:17:32 PM
|
|
awesome replies, thanks everybody!
|
|
0
|
|
|
|
Reply
|
o.simon (7)
|
4/11/2011 3:17:25 PM
|
|
|
8 Replies
32 Views
(page loaded in 0.146 seconds)
|