[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


(APPLY <map-function> <function> <args>))

This has probably been noted before, but just in case it has not...
A user here was defining a function which uses the MAP function as shown
above, when that function is compiled, <args> will be clobbered.  Same
thing happens in Zetalisp.  This works interpreted and works in
another implementation, interpreted or compiled, and nothing in the
language definition forbids it, so I think its a bug.  Having being
smitten by the LOOP "plague" (as a net contributed has termed it...),
it did not occur to me to use mapping function this way but it does
seem to be an elegant and concise definition.  The fix in this case,
since the sublists were not clobbered (only the top level lists) is to
do a COPY-LIST of <arg> first, but then it does seem to defeat the

;;; -*- Package: SYMBOLICS-COMMON-LISP -*-
;; Running Realease 6.1 and FEP 127.

(defvar lst '((a b c) (d e f) (g h i)))

;; Returns the list of list of the nth element of each sublist
(defun mapbug (lst2)
  (apply 'mapcar #'list lst2))

command: ,lst
((A B C) (D E F) (G H I))

command: (mapbug lst)
((A D G) (B E H) (C F I))

command: ,lst