[pro] About &aux

Tamas K Papp tkpapp at gmail.com
Mon Jun 13 12:36:09 UTC 2011


On Sun, 12 Jun 2011 10:00:45 -0400, Daniel Weinreb wrote:

> I, myself, really dislike &aux.  It has been so long since I have seen
> it that I have forgotten that it even exists.  We never use it; and I
> should add that to our style guide.

I was wondering about the use of &aux a while ago, so I asked on c.l.l:

http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/586ca399d6b7e0b4/ad1bfb5a629597cb

The examples convinced me that it is occasionally useful.  However, as
the previous thread shows, it is still not part of my "active" CL
vocabulary, so sometimes I don't think of it as a solution.  Maybe
that will change and I will remember it the next time I need it.

> I don't even like
> 
> (let (a b c) ...)

I find (let (a b c) ...) very useful occasionally.  I am curious how
you would write this without it:

(defun map-as-rows (function vector)
  "Map elements of vector, collect into a matrix."
  (let ((vector-length (length vector))
        result
        result-length)
    (dotimes (index vector-length)
      (let ((result-row (funcall function (aref vector index))))
        (if (zerop index)
            (setf result-length (length result-row)
                  result (make-array (list vector-length result-length)))
            (assert (= (length result-row) result-length) ()
                    "Incompatible length of results."))
        (replace (make-array result-length
                             :displaced-to result
                             :displaced-index-offset (* index result-length))
                 result-row)))
    result))

(map-as-rows (lambda (x) (vector x (expt x 2))) #(1 2 3 4))

#2A((1 1) 
    (2 4)
    (3 9)
    (4 16))

The only way I see is traversing the results one more time to form the matrix.

Best,

Tamas






More information about the pro mailing list