Re: about PCL's once-only



"Captain Obvious" <udodenko@xxxxxxxxxxxxxxxxxxxxx> 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 {}.
.