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

scoping...



#|
I know I'm an idiot for not understanding the nuances of scoping et al,
but...

I have something like:
|#

(when (find-menu "Foobar") (menu-deinstall (find-menu "Foobar")))

(defparameter foobar (make-instance 'menu :menu-title "Foobar"))
(apply #'add-menu-items foobar
  (let ((activities #(A B C))
        (items nil)
        activity)
    ;(declare (<WHAT GOES HERE?!!!> activity)
    (dotimes (i (length activities) (nreverse items))
      (setq activity (aref activities i))
      (push
        (make-instance 'menu-item
          :menu-item-title (string activity)
          :menu-item-action
          #'(lambda ()
              (print activity)))
        items))))

(menu-install foobar)

#|

This results in a list of menu-items, each with the correct title, but the
functions all affect the LAST activity, rather than the ith.  ie, All of
the menu-items print C.

I understand that the variable activity is incorrectly scoped, but what do
I do to fix it?

|#
-- 
--
-- "TANSTAAFL" Rich lynch@ils.nwu.edu