Hello,
Suppose I want to store a value for later use. I define it using:
(define balance 10)
Later on I apply a function to #'balance and want to store the result for later use. The old value of #'balance is useless, and I do not want to introduce a new name every time for the result of function application, so I do either one of the followings. I would like to ask what is the real difference between the followings:
(define balance (some-function balance))
vs
(set! balance (some-function balance))
Thanks.
basic question about define and set!
-
- Posts: 447
- Joined: Sat Jun 28, 2008 7:49 am
- Location: Austin, TX
- Contact:
Re: basic question about define and set!
DEFINE actually creates a global variable if one doesn't already exist before setting it to a new value. SET! simply sets an already-existing variable to a new value (mutation).
See http://www.schemers.org/Documents/Stand ... _sec_5.2.1
(Note that phpBB botches the URL above. You might have to copy and paste it directly into your browser.)
See http://www.schemers.org/Documents/Stand ... _sec_5.2.1
(Note that phpBB botches the URL above. You might have to copy and paste it directly into your browser.)
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Re: basic question about define and set!
Code: Select all
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-8.html#%_sec_5.2.1