chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] the effect of set! on the top-level namespace


From: Kon Lovett
Subject: Re: [Chicken-users] the effect of set! on the top-level namespace
Date: Mon, 15 Oct 2007 08:13:53 -0700


On Oct 15, 2007, at 7:42 AM, Terrence Brannon wrote:

I would like to know:
* what is happening to the symbol afunc in line 1 versus line 3. In
particular is the same memory location being over-written?

Yes.

* Also, in line 2 is first-func being set to a value which is not destroyed by
the set! call in line 3?

Yes.

* I think I was anticipating that first-func would assume the behavior
of second-func once afunc was re-defined.

No. Scheme is "by-value" not "by-name".

* Finally, there is no need to make things complicated by using set!
since the define version has the same behavior. But for some code I am
writing personally, I have to use set! because define inside a let
does not seem to affect the top-level the way I need it to.

Per Scheme spec.

The idiom is:

(define foo)
(let (foo-local-vars ...)
  foo-local-defs ...
  (set! foo (lambda ...)) )


(set! afunc (lambda (x) (+ x 5)))      ;;; line 1
(set! first-func afunc)
(set! afunc (lambda (x) (* x 1000)))  ;;; line 3
(set! second-func afunc)

(first-func 1)
(second-func 1)

(afunc 1) ; same as second-func

;;; define version
(define afunc (lambda (x) (+ x 5)))
(define first-func afunc)
(define afunc (lambda (x) (* x 1000)))
(define second-func afunc)

(first-func 1)
(second-func 1)

(afunc 1) ; same as second-func


_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users

Best Wishes,
Kon






reply via email to

[Prev in Thread] Current Thread [Next in Thread]