Re: [pro] Sub-function free variable binding differences between Scheme and CL

2012-03-05 Thread Stas Boukarev
Burton Samograd burton.samog...@gmail.com writes:

 Hello,

 I am curently translating the logic circuit simulator code from SICP
 into Common Lisp and have run into a snag that I would like to ask
 about.

 The Scheme code is as follows from section 3.3.4 (page 223 of my
 hardcover edition):

 (define (and-gate a1 a2 output)
 (define (and-action-procedure)
 (let ((new-value
(locical-and (get-signal a1) (get-signal a2
  (after-delay and-gat-delay
   (lambda ()
   (set-signal! output new-value)
  (add-action! a1 and-action-procedure)
  (add-action! a2 and-action-procedure))

 The code basically binds the local function and-action-procedure into
 a list of functions in a1 and a2 which are then called by another
 routine later to perform the action when a value is set on the wire.

 My translated Common Lisp code is:

 (defun make-and-gate (a1 a2 output)
   (flet ((logical-and (a b)
(if (= a 1) b a))
  (and-action-proc ()
(let ((new-value (logical-and (get-signal a1) (get-signal a2
  (set-signal output new-value
 (add-action a1 #'and-action-proc)
 (add-action a2 #'and-action-proc)))
You should use LABELS instead of FLET, FLET doesn't make its definitions
available inside definitions so the call logical-and in and-action-proc
can't find logical-and.

And seriously, writing to the _pro_ mailing list to ask trivial questions?

-- 
With best regards, Stas.

___
pro mailing list
pro@common-lisp.net
http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro


Re: [pro] Sub-function free variable binding differences between Scheme and CL

2012-03-05 Thread Stas Boukarev
Burton Samograd burton.samog...@gmail.com writes:

 I apologize, my original code was using labels but I copied the one
 using flet for this question.  Please assume that I am using labels;
 the variable binding question still stands.

With labels, the code is right, that means either you're not telling
something else again, or the problem is in another place in the code.

-- 
With best regards, Stas.

___
pro mailing list
pro@common-lisp.net
http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro