Subject: Re: DON'T READ IF YOU NEED TO KEEP YOUR DEAD IN THE SAND (Arc info inside)
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 12 Feb 2008 06:28:44 -0600
Newsgroups: comp.lang.lisp
Message-ID: <_q6dndKLnPRhDSzanZ2dnUVZ_vOlnZ2d@speakeasy.net>
jayessay  <nospam@foo.com> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) writes:
| > I muchly prefer my own #$ readmacro
| > [or one of the many similar variants discussed here last December]:
| >     > (mapcar #$(+ (* 100 $2) $1) '(1 2 3 4) '(5 6 7 8) '(9 10 11 12))
| >     (501 602 703 804)
| 
| What happens with the last list here?
+---------------

It's ignored. Or, rather, it's bound to $3, but $3 is ignored! ;-}  ;-}

Here's the definition of my current simpleminded version of #$:

    (defun set-sharp-dollar-reader ()
      (flet ((sharp-dollar-reader (s c p)
	       (declare (ignore c p))
	       (let* ((form (read s t nil t)))
		 `(lambda (&optional $1 $2 $3 $4 $5 $6 $7 $8 $9 &rest $*)
		    (declare (ignorable $1 $2 $3 $4 $5 $6 $7 $8 $9 $*))
		    ,@(if (and (consp form) (consp (car form)))
			form
			(list form))))))
	(set-dispatch-macro-character #\# #\$ #'sharp-dollar-reader)))

Now in the thread last December, it was suggested that it might be
better to walk the FORM for variables of the form "${integer}" and
only declare arguments from $1 up to the highest seen [and then add
the &REST $* after that]. Yeah, that would be better, but I haven't
done it yet. Not enough round tuits...  ;-}


-Rob

p.s. The reason for the IF inside the LAMBDA may be non-obvious; it's
just a convenience hack to provide an implicit PROGN sometimes, e.g.:

    > (mapcar #$((format t "Thrice ~a...~%" $1) (* $1 3)) (iota 5))
    Thrice 0...
    Thrice 1...
    Thrice 2...
    Thrice 3...
    Thrice 4...
    (0 3 6 9 12)
    > 

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607