Re: How Function Create Variables?




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?

.



Relevant Pages

  • Re: Good C programming style
    ... > I'm thinking about a good programming style, pros and cons of some topics. ... this has nothing to do with indentation... ... > - function variables: they're used to java, so no pointers. ...
    (comp.lang.c)
  • Re: define and assignment
    ... All values are pointers to objects. ... Some values are pointers to objects (e.g. cons cells), ... are immediate. ... the Scheme specification even goes one step further ...
    (comp.lang.scheme)
  • Re: How Function Create Variables?
    ... d> don't know how can this function create these new cons cells. ... in Lisp because everything is passed as a pointer. ... just pointers, you can have many pointers pointing to single value, or just ...
    (comp.lang.lisp)
  • Re: function reading hour register either in 12 or 24 hour formats and returning properly
    ... What are the pros and cons of passing two pointers in the ...
    (comp.lang.c)
  • Re: When is Xah going to ease up on Emacs...
    ... and the notion of head also appear in lisp. ... is still a tree or a nested list. ... So, suppose you invented a lisp language, so that there's no cons, but ... So this means, in this language the head, or non-leaf nodes of a tree, ...
    (comp.lang.lisp)