Re: How Function Create Variables?
- From: "daidongLY@xxxxxxxxx" <daidongLY@xxxxxxxxx>
- Date: Mon, 30 Jul 2007 04:42:22 -0700
each time you call CONS it creates a new cell.
if thing is CONS, it gets copied -- you create a new CONS calling CONS
function.
if thing is ATOM (not-a-cons), old value is referenced.
OH... I get it now...
The new variables are created by CONS function, and the CONS function
can automatically create
new cons Object as your code show.
Some code here:
(defvar *x* '( (a b) (c d) ))
(setf *y* (copy-tree *x*))
(setf (first (first *y*)) 'e)
Then *x* and *y* are different.
*x* => ( (A B) (C D))
*y* => ( (E B) (C D))
No share atoms between *x* and *y* !
Does this mean ATOM (like 'a or 'e in *x* and *y*) also is copied not
just be referenced? I mean that if ATOM is only referenced, *x* and
*y* should be the same, because their (first (first ...)) point the
same Place in memoery.
in Lisp semantics is pretty same, but it doesn't need to specially denote
pointers as everything is a pointer, indirections are done automatically,
and memory management is done automatically.
as for variables, i hope at this point you see that they are not much
important and they do not participate in creation of anything -- they are
just pointers, you can have many pointers pointing to single value, or just
pointing to nothing.
"Each time a function is called, Lisp creates new bindings to hold the
arguments passed by the function's caller"
The Book-- 'Practical Lisp'
Does this sentence mean that every time a function is called, Lisp
will create new variables to hold the value( or pointer? ) of the
arguments?
.
- Follow-Ups:
- Re: How Function Create Variables?
- From: Alex Mizrahi
- Re: How Function Create Variables?
- References:
- How Function Create Variables?
- From: daidongLY@xxxxxxxxx
- Re: How Function Create Variables?
- From: Alex Mizrahi
- How Function Create Variables?
- Prev by Date: Re: shootout: implementing an interpreter for a simple procedural language Minim
- Next by Date: Re: Need some help.
- Previous by thread: Re: How Function Create Variables?
- Next by thread: Re: How Function Create Variables?
- Index(es):
Relevant Pages
|