Actually, looking through my code base, I find I've used &aux half a dozen times in the last ten years. Always in a BOA constructor.
- n
On 11 Jun 2011, at 10:42, Nick Levine wrote:
Actually, looking through my code base, I find I've used &aux half a dozen times in the last ten years. Always in a BOA constructor.
I have a tendency to use &aux more and more often, even outside of BOA constructors. There are two main reasons:
- It saves horizontal space in the source code. Compare the following two pieces of code:
(defun foo1 (a b c &aux d e f) ...)
(defun foo2 (a b c) (let (d e f) ...))
The use of &aux saves one level of indentation here, which can sometimes make a piece of code look more beautiful.
- The more important reason is that I sometimes want to derive some value from an argument that is "very close" to the value of the original argument. Here is an example:
(defun required-args (args) (loop for arg in args until (member arg lambda-list-keywords) collect arg))
(defun process-method-arguments (args &aux (required-args (required-args args))) ...)
This is, of course, only a subjective quality, but in cases like this, the function actually only wants to do something with the required arguments for a method definition, but it also wants the client code not to worry too much about what it passes to the function. To me, &aux perfectly expresses that idea.
Best, Pascal
-- Pascal Costanza The views expressed in this email are my own, and not those of my employer.
Pascal Costanza wrote:
- The more important reason is that I sometimes want to derive some
value from an argument that is "very close" to the value of the original argument. Here is an example:
I would go even farther than that. Sometimes, you want to slightly frob the original argument and not use it anymore afterwards. In such situations, you can even use the same variable name (one might consider this either very stylized or very ugly ;-).
CL-USER> (defun foo (arg &aux (arg (1+ arg))) arg) FOO CL-USER> (foo 1) 2
I find &AUX useful for setting global parameters, like:
(defun read-data (data-source &aux (*read-default-float-format* 'double-float)) ...)
I think it better expresses the change than in a LET* form or using WITH at the top of a LOOP.
Tom ---------------------------------------------------------------- Thomas M. Hermann Odonata Research LLC http://www.odonata-research.com/ http://www.linkedin.com/in/thomasmhermann
On Sat, Jun 11, 2011 at 6:03 AM, Didier Verna didier@lrde.epita.fr wrote:
Pascal Costanza wrote:
- The more important reason is that I sometimes want to derive some
value from an argument that is "very close" to the value of the original argument. Here is an example:
I would go even farther than that. Sometimes, you want to slightly frob the original argument and not use it anymore afterwards. In such situations, you can even use the same variable name (one might consider this either very stylized or very ugly ;-).
CL-USER> (defun foo (arg &aux (arg (1+ arg))) arg) FOO CL-USER> (foo 1) 2
-- Resistance is futile. You will be jazzimilated.
Scientific site: http://www.lrde.epita.fr/~didier Music (Jazz) site: http://www.didierverna.com
pro mailing list pro@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro