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

Re: Apply

>From: owens@cs.uchicago.edu
>Date: Wed, 12 Aug 92 11:59:16 CDT
>To: bill@cambridge.apple.com
>Subject: Re: Apply
>Newsgroups: comp.lang.lisp.mcl
>Organization: Dept of Computer Science, The Univ of Chicago
>In article <9208121537.AA03113@cambridge.apple.com> you write:
>>(defun make-menu-items (items)
>>  (let (menu-items)
>>    (dolist (item items)
>>      (push (make-instance ...
>>              :attached-function
>>              #'(lambda (window)
>>                  (declare (ignore window))
>>                  (print item)))
>>            menu-items)
>>      ...)))
>Bill, I almost posted this exact code fragment, but then I thought of
>the buggy code that Rao posted the other day, and I couldn't remember
>whether dolist was guaranteed to create a fresh binding for each
>iteration.  Does your code create an :attached-function that, for each
>of the menu items, prints the value taken on by ITEM during the last
>iteration of the DOLIST?

As pointed out by Kim Barrett and Bob Cassells, my code is wrong.
You need to create a fresh binding or use a mapping function.