From ...
Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!128.39.3.168!uninett.no!Norway.EU.net!not-for-mail
From: Erik Naggum
Newsgroups: comp.lang.lisp
Subject: Re: *Why* is LISP better?
Date: 05 Aug 2002 13:15:36 +0000
Organization: Naggum Software, Oslo, Norway
Lines: 49
Message-ID: <3237542136210443@naggum.no>
References: <3un39.25012$Kl6.1593188@bgtnsc04-news.ops.worldnet.att.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: oslo-nntp.eunet.no 1028553336 21491 193.71.199.50 (5 Aug 2002 13:15:36 GMT)
X-Complaints-To: abuse@KPNQwest.no
NNTP-Posting-Date: 5 Aug 2002 13:15:36 GMT
Mail-Copies-To: never
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2
Xref: archiver1.google.com comp.lang.lisp:37276
* "Icosahedron"
| Call it aesthetics or bullsh*t, but I think it a bit ugly to have:
| (setf myfunc (lambda (x) (+ 1 x)) and then have to invoke it with
| (funcall myfunc) rather than just (myfunc)
But unless you are severely braindamaged, you just do not do such things.
Yes, it is can be inconvenient to do profoundly stupid things. This is a
good thing. You will not appreciate this while you are doing profoundly
stupid things, however.
If you have variables that contain functions and you have a distaste for
`funcall´ (but apparently not for `apply´, which I always find odd), you use
your intelligence and your programming skills to do two things at once:
declare the variable to hold functions, and make funcalling them easier.
One simple solution is
(defmacro with-functions (bindings &body body)
"Declare each member of the (designator for a) list of symbols in BINDINGS
a function, and create local macros that take care of the funcall in BODY."
(if (and bindings (symbolp bindings))
`(with-functions (,bindings) ,@body)
`(macrolet ,(mapcar (lambda (symbol)
`(,symbol (&rest arguments)
`(funcall ,',symbol ,@arguments)))
bindings)
(declare (type function ,@bindings))
,@body)))
If you now write
(defun whatever (function a b c)
(with-functions (function)
(function a b c)))
the compiler will actually see exactly the same as if you had written
(defun whatever (function a b c)
(declare (type function function))
(funcall function a b c))
This may, of course, illustrate the power of macros more than it illustrates
how you can "improve" your programming style with macros.
--
Erik Naggum, Oslo, Norway
Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.