Subject: Re: *Why* is LISP better? From: Erik Naggum <firstname.lastname@example.org> Date: 05 Aug 2002 13:15:36 +0000 Newsgroups: comp.lang.lisp Message-ID: <email@example.com> * "Icosahedron" <firstname.lastname@example.org> | 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.