From: neo88
Subject: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407060359.4a9a2be8@posting.google.com>
I am still a bit of a newbie to the Lisp paradigm, although I have
been programming in it for a few months now, I still don't feel as
comfortable with it as do other langauges like C++. I came aupon a
question a few days ago, and can't seem to find the answer to it in
any of the books or documentation I have about Lisp. The question is:
Does Lisp a form of memory allocation?
C has malloc(), C++ has the new and this pointer, etc. What about
Lisp? I still haven't seen anything like that when I have been
programming in it. The closest function I have seen to memory
allocation is (setq). Does Lisp have anything similar to the pointers
introduced by C++? How do you refrence an object in Lisp? Can you do
something similar to the following:

(defun stuff(anything)
   (let &this_thing = (anything))
       (print list(&this_thing)(anything)))

I know that's a bit sloppy, and I'm not sure if the ouput is quite
right, but what I'm trying to do is refrence a function to a list. Can
it be done in a way similar to that?
I apologize if I have overloaded you guys with questions, I just
couldn't find anything about this in any of the resources that I have.
Thanks for any answers.

neo88

From: Gisle Sælensminde
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <slrncela1b.mvg.gisle@ginkgo.ii.uib.no>
In article <····························@posting.google.com>, neo88 wrote:
> I am still a bit of a newbie to the Lisp paradigm, although I have
> been programming in it for a few months now, I still don't feel as
> comfortable with it as do other langauges like C++. I came aupon a
> question a few days ago, and can't seem to find the answer to it in
> any of the books or documentation I have about Lisp. The question is:
> Does Lisp a form of memory allocation?
> C has malloc(), C++ has the new and this pointer, etc. What about
> Lisp? I still haven't seen anything like that when I have been
> programming in it. The closest function I have seen to memory
> allocation is (setq). Does Lisp have anything similar to the pointers
> introduced by C++? How do you refrence an object in Lisp? Can you do
> something similar to the following:

Everytime you call a funtcion that constructs data structure, like cons, list,
make-array or make-hash-table, the fucntion will implicitly do memory 
allocation, and will return an (implicit) reference to the newly allocated 
datastructure.  Also, several functions implicitly allocate the memory they 
need. Of historical reasons this is called consing in lisp, named after the 
cons-function that allocates a cons-cell , which is the building blocks for 
lists.

> 
> (defun stuff(anything)
>    (let &this_thing = (anything))
>        (print list(&this_thing)(anything)))

I interpret the above as you want a list of two elements, where both points to
the same object. Then it will be as easy as:

(defun stuff (anything)
  (list anything anything))

(defparameter *mylist* (stuff (string "abc")))

(print *mylist*)
=> ("abc" "abc")

Now you have a list where both elements points to the same object. 
If you change a character of the first element in the list you will see it:

(setf (char (first *mylist*) 0) #\1)

If you on the other hand writes 

(setf (first *mylist*) "123")

You will replace the first element of the list with a new object

(print *mylist*)

("123" "1bc")

-- 
--
Gisle S�lensminde
Computational biology unit, University of Bergen, Norway
Email: ·····@cbu.uib.no
From: Pascal Costanza
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <cce86j$pbk$1@f1node01.rhrz.uni-bonn.de>
neo88 wrote:

> I am still a bit of a newbie to the Lisp paradigm, although I have
> been programming in it for a few months now, I still don't feel as
> comfortable with it as do other langauges like C++. I came aupon a
> question a few days ago, and can't seem to find the answer to it in
> any of the books or documentation I have about Lisp. The question is:
> Does Lisp a form of memory allocation?

Memory is usually allocated implicitly in Lisp. So, for example, when 
you say (list 4 5 6), this tells the Lisp runtime system to implicitly 
create a singly-linked list structure, and you don't have to take care 
of the internal mechanisms to do that. (You also don't have to take care 
of freeing up memory because Lisp has automatic memory management, best 
known under the more traditional name garbage collection.)

There are, however, some explicit memory allocation functions. They 
don't work on a low level, as malloc does, but are rather specific to 
the things you want to create. So, for example, you have make-array for 
arrays, make-hash-table for hash tables, and so on. You also have 
make-instance for creating instances of your own classes (as in OOP). In 
general, if a function name starts with "make-" it is very likely a 
memory allocation function.

> C has malloc(), C++ has the new and this pointer, etc. What about
> Lisp? I still haven't seen anything like that when I have been
> programming in it. The closest function I have seen to memory
> allocation is (setq). Does Lisp have anything similar to the pointers
> introduced by C++? How do you refrence an object in Lisp?

References are also implicit in Lisp (at least in Common Lisp and Scheme 
- there have been Lisp dialects with low-level references, but they are 
not in wide use anymore AFAICS). setq doesn't allocate, it just sets a 
variable to a value. So, for example, you can create a hash table as 
follows:

(setq table (make-hash-table))

The variable table then stores a reference to the hash table created for 
setq's second argument. By default, all variables store references, and 
not direct values. That's even the case for values of type number, 
boolean, strings, and so on. (And, no, it's not necessarily ineffecient, 
but that's another topic.) Therefore, there are no explicit 
dereferencing operators, or some such, because that's already the 
default way of dealing with values and objects anyway.

(BTW, the code above is strictly incorrect because in Lisp, you are 
required to first declare your variables before assigning or reading 
them. So more correct would be:

(let ((table (make-hash-table)))
    ; here you do the things you want to do with your hash table
    ...)

> I know that's a bit sloppy, and I'm not sure if the ouput is quite
> right, but what I'm trying to do is refrence a function to a list. Can
> it be done in a way similar to that?

I don't understand what you want to achieve here, sorry. In general, you 
cannot access the variables that you have passed to a function. So:

(defun stuff (i)
   (setq i (+ i 1)))

(let ((v 0))
   (stuff v)
   (print v))

...this doesn't do what you may expect because the variable i in 
function stuff is different from the variable v in the section that 
calls stuff. There are no call-by-reference parameters in Lisp. Instead, 
you use return values:

(defun stuff (i)
   (+ i 1)) ; this is the return value

(let ((v 0))
   (setq v (stuff v))
   (print v))

This takes a little getting used to, but turns out as more flexible in 
many cases. (It's possible to write macros that change variables 
directly, so it's certainly possible to achieve the same effect as 
call-by-reference, but that's for macro programming.)

I hope this helps.


Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407061210.722c1f6c@posting.google.com>
Pascal Costanza <········@web.de> wrote in message news:<············@f1node01.rhrz.uni-bonn.de>...
> neo88 wrote:
> 
> > I am still a bit of a newbie to the Lisp paradigm, although I have
> > been programming in it for a few months now, I still don't feel as
> > comfortable with it as do other langauges like C++. I came aupon a
> > question a few days ago, and can't seem to find the answer to it in
> > any of the books or documentation I have about Lisp. The question is:
> > Does Lisp a form of memory allocation?
> 
> Memory is usually allocated implicitly in Lisp. So, for example, when 
> you say (list 4 5 6), this tells the Lisp runtime system to implicitly 
> create a singly-linked list structure, and you don't have to take care 
> of the internal mechanisms to do that. (You also don't have to take care 
> of freeing up memory because Lisp has automatic memory management, best 
> known under the more traditional name garbage collection.)
> 
Is this type of garbage collection the same as in Java? 
> There are, however, some explicit memory allocation functions. They 
> don't work on a low level, as malloc does, but are rather specific to 
> the things you want to create. So, for example, you have make-array for 
> arrays, make-hash-table for hash tables, and so on. You also have 
> make-instance for creating instances of your own classes (as in OOP). In 
> general, if a function name starts with "make-" it is very likely a 
> memory allocation function.
> 
Can Lisp abstract a function to a lower level? What if you wanted to
do a hard reference to the actual physical memory registor? Or would
you never have to do that with Lisp?
> > C has malloc(), C++ has the new and this pointer, etc. What about
> > Lisp? I still haven't seen anything like that when I have been
> > programming in it. The closest function I have seen to memory
> > allocation is (setq). Does Lisp have anything similar to the pointers
> > introduced by C++? How do you refrence an object in Lisp?
> 
> References are also implicit in Lisp (at least in Common Lisp and Scheme 
> - there have been Lisp dialects with low-level references, but they are 
> not in wide use anymore AFAICS). setq doesn't allocate, it just sets a 
> variable to a value. So, for example, you can create a hash table as 
> follows:
> 
> (setq table (make-hash-table))
> 
> The variable table then stores a reference to the hash table created for 
> setq's second argument. By default, all variables store references, and 
> not direct values. That's even the case for values of type number, 
> boolean, strings, and so on. (And, no, it's not necessarily ineffecient, 
> but that's another topic.) Therefore, there are no explicit 
> dereferencing operators, or some such, because that's already the 
> default way of dealing with values and objects anyway.
> 
> (BTW, the code above is strictly incorrect because in Lisp, you are 
> required to first declare your variables before assigning or reading 
> them. So more correct would be:
> 
> (let ((table (make-hash-table)))
>     ; here you do the things you want to do with your hash table
>     ...)
> 
> > I know that's a bit sloppy, and I'm not sure if the ouput is quite
> > right, but what I'm trying to do is refrence a function to a list. Can
> > it be done in a way similar to that?
> 
> I don't understand what you want to achieve here, sorry. In general, you 
> cannot access the variables that you have passed to a function. So:
> 
> (defun stuff (i)
>    (setq i (+ i 1)))
> 
> (let ((v 0))
>    (stuff v)
>    (print v))
> 
> ...this doesn't do what you may expect because the variable i in 
> function stuff is different from the variable v in the section that 
> calls stuff. There are no call-by-reference parameters in Lisp. Instead, 
> you use return values:
> 
> (defun stuff (i)
>    (+ i 1)) ; this is the return value
> 
> (let ((v 0))
>    (setq v (stuff v))
>    (print v))
> 
> This takes a little getting used to, but turns out as more flexible in 
> many cases. (It's possible to write macros that change variables 
> directly, so it's certainly possible to achieve the same effect as 
> call-by-reference, but that's for macro programming.)
> 
Yeah it does. I'm still not used to the way Lisp is written or how it
looks, I have been a C++ and Java programmer for the past five years.
I think I might be catching on though. :)
> I hope this helps.
> 
It did thanks a lot!!
> 
> Pascal

neo88
From: Christopher C. Stacy
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <uk6xgop7q.fsf@news.dtpq.com>
>>>>> On 6 Jul 2004 13:10:25 -0700, neo88  ("neo88") writes:
 >> 
 neo88> Is this type of garbage collection the same as in Java? 

Java got the idea from Lisp.

 neo88> Can Lisp abstract a function to a lower level? What if you
 neo88> wanted to do a hard reference to the actual physical memory
 neo88> registor? Or would you never have to do that with Lisp?

The ANSI Common Lisp standard does not provide a way to do that.
But every actual Lisp implementation gives you a way to do that.

It is not something that you would normally do in a Lisp program.

(For that matter, it is not something that you would normally 
do in most programs in any programming language.)
From: Gisle Sælensminde
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <slrncem3g7.41t.gisle@kaktus.ii.uib.no>
In article <····························@posting.google.com>, neo88 wrote:
> Pascal Costanza <········@web.de> wrote in message news:<············@f1node01.rhrz.uni-bonn.de>...
>> neo88 wrote:
>> 
>> > I am still a bit of a newbie to the Lisp paradigm, although I have
>> > been programming in it for a few months now, I still don't feel as
>> > comfortable with it as do other langauges like C++. I came aupon a
>> > question a few days ago, and can't seem to find the answer to it in
>> > any of the books or documentation I have about Lisp. The question is:
>> > Does Lisp a form of memory allocation?
>> 
>> Memory is usually allocated implicitly in Lisp. So, for example, when 
>> you say (list 4 5 6), this tells the Lisp runtime system to implicitly 
>> create a singly-linked list structure, and you don't have to take care 
>> of the internal mechanisms to do that. (You also don't have to take care 
>> of freeing up memory because Lisp has automatic memory management, best 
>> known under the more traditional name garbage collection.)
>> 
> Is this type of garbage collection the same as in Java? 
>> There are, however, some explicit memory allocation functions. They 
>> don't work on a low level, as malloc does, but are rather specific to 
>> the things you want to create. So, for example, you have make-array for 
>> arrays, make-hash-table for hash tables, and so on. You also have 
>> make-instance for creating instances of your own classes (as in OOP). In 
>> general, if a function name starts with "make-" it is very likely a 
>> memory allocation function.
>> 
> Can Lisp abstract a function to a lower level? What if you wanted to
> do a hard reference to the actual physical memory registor? Or would
> you never have to do that with Lisp?

In my experience you will in practice never need to this kind of lowlevel
stuff to get things done in lisp. On modern operating systems you access
the hardware through function calls or devices. That means that you don't
need to access the raw bits of memory directly. You still need to control
how the bits are written to disk or the network, but Common Lisp has 
what you need to do that. 

There are still some places where you need some bitfiddling, like in 
embedded systems, and for cryptography and compression algorithms. In
those cases you will often need some implementation-specific stuff in
the Lisp-system to get it done (efficiently). Most people don't write
such stuff themselves, but uses code written by others.  

--
Gisle S�lensminde
Computational biology unit, University of Bergen, Norway
Email: ·····@cbu.uib.no
From: Christopher C. Stacy
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <ufz84obqm.fsf@news.dtpq.com>
>>>>> On 6 Jul 2004 20:38:57 GMT, Gisle S�lensminde ("Gisle") writes:
 Gisle> There are still some places where you need some bitfiddling, like in 
 Gisle> embedded systems, and for cryptography and compression algorithms. In
 Gisle> those cases you will often need some implementation-specific stuff in
 Gisle> the Lisp-system to get it done (efficiently). Most people don't write
 Gisle> such stuff themselves, but uses code written by others.  

Haven't people been writing efficient encryption routines 
in ANSI Common Lisp (without resorting to such tricks)?
From: Gisle Sælensminde
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <slrncemvv5.7tb.gisle@apal.ii.uib.no>
In article <·············@news.dtpq.com>, Christopher C. Stacy wrote:
>>>>>> On 6 Jul 2004 20:38:57 GMT, Gisle S�lensminde ("Gisle") writes:
>  Gisle> There are still some places where you need some bitfiddling, like in 
>  Gisle> embedded systems, and for cryptography and compression algorithms. In
>  Gisle> those cases you will often need some implementation-specific stuff in
>  Gisle> the Lisp-system to get it done (efficiently). Most people don't write
>  Gisle> such stuff themselves, but uses code written by others.  
> 
> Haven't people been writing efficient encryption routines 
> in ANSI Common Lisp (without resorting to such tricks)?
> 

I haven't seen many encryption routines, but cl-md5 
(still in the cryptography domain) compiles to pure common lisp if
you are on non-cmucl compilers, while it use a lot of cmucl-specific 
stuff on cmucl. Apperently it gains a lot of speed on cmucl. The 
implementation-specific stuff is functions to ensure hardware shifts
and rotate. In addition it is using standard type definitions and 
inline declarations a lot.

--
Gisle S�lensminde
Computational biology unit, University of Bergen, Norway
Email: ·····@cbu.uib.no
From: Christophe Rhodes
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <sqwu1gi4f2.fsf@cam.ac.uk>
Gisle Sælensminde <·····@apal.ii.uib.no> writes:

> I haven't seen many encryption routines, but cl-md5 
> (still in the cryptography domain) compiles to pure common lisp if
> you are on non-cmucl compilers, while it use a lot of cmucl-specific 
> stuff on cmucl. Apperently it gains a lot of speed on cmucl. The 
> implementation-specific stuff is functions to ensure hardware shifts
> and rotate. In addition it is using standard type definitions and 
> inline declarations a lot.

Note that the pure common lisp version, in sbcl, compiles to the same
(well, in fact slightly more efficient) code as the cmucl-specific
stuff compiles to on cmucl.  See also Nathan Froyd's implementation of
SHA1, and discussions on sbcl-devel (mostly from Alexey Dejneka) about
"modular arithmetic".

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)
From: Gisle Sælensminde
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <slrncengln.d94.gisle@ginkgo.ii.uib.no>
In article <··············@cam.ac.uk>, Christophe Rhodes wrote:
> 
> Note that the pure common lisp version, in sbcl, compiles to the same
> (well, in fact slightly more efficient) code as the cmucl-specific
> stuff compiles to on cmucl.  See also Nathan Froyd's implementation of
> SHA1, and discussions on sbcl-devel (mostly from Alexey Dejneka) about
> "modular arithmetic".

Nice to hear that my knowledge was outdated, at least for SBCL.

-- 
--
Gisle S�lensminde
Computational biology unit, University of Bergen, Norway
Email: ·····@cbu.uib.no
From: Alexey Dejneka
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <m3eknn40z2.fsf@comail.ru>
Hello,

Christophe Rhodes <·····@cam.ac.uk> writes:

> Gisle S�lensminde <·····@apal.ii.uib.no> writes:
> 
> > I haven't seen many encryption routines, but cl-md5 
> > (still in the cryptography domain) compiles to pure common lisp if
> > you are on non-cmucl compilers, while it use a lot of cmucl-specific 
> > stuff on cmucl. Apperently it gains a lot of speed on cmucl. The 
> > implementation-specific stuff is functions to ensure hardware shifts
> > and rotate.

... and LOGNOT (which does not preserve 32 bitness).

> > In addition it is using standard type definitions and 
> > inline declarations a lot.
> 
> Note that the pure common lisp version, in sbcl,

SB-MD5 still uses the ROTATE-BYTE function, so it is not quite a pure
CL.

-- 
Regards,
Alexey Dejneka

"Alas, the spheres of truth are less transparent than those of
illusion." -- L.E.J. Brouwer
From: Pascal Costanza
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <ccgner$11km$1@f1node01.rhrz.uni-bonn.de>
neo88 wrote:

> Is this type of garbage collection the same as in Java? 

Yes.

> Can Lisp abstract a function to a lower level? What if you wanted to
> do a hard reference to the actual physical memory registor? Or would
> you never have to do that with Lisp?

In general, this is possible, but that's not a useful answer if you are 
referring to Lisp as a family of languages. The Common Lisp dialect was 
designed as a common denominator for a range of Lisp dialects and the 
goal was to include the things that everybody in the Lisp community can 
agree on. Low-level access to the machine level are by their very nature 
platform dependent, so they don't belong in such a standard. Machines 
differ a lot in such respects. You have to resort to a concrete Common 
Lisp implementation to see what it offers. (There exists a quasi 
standard for accessing C code - cf. UFFI.)

> Yeah it does. I'm still not used to the way Lisp is written or how it
> looks, I have been a C++ and Java programmer for the past five years.
> I think I might be catching on though. :)

My best wishes for that and welcome to the club. ;)

However, here is a piece of advice: Don't try to work bottom-up by 
trying very hard to simulate low-level details of other languages. It's 
better to try to understand what the big picture is for creating 
full-scale applications in Lisp. There are a number of excellent 
tutorials on the web that give you good ideas in this regard. See 
http://alu.cliki.net/Education for a start.


Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)
From: ·········@random-state.net
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <cceggu$1rc46$1@midnight.cs.hut.fi>
Pascal Costanza <········@web.de> wrote:

> This takes a little getting used to, but turns out as more flexible in 
> many cases. (It's possible to write macros that change variables 
> directly, so it's certainly possible to achieve the same effect as 
> call-by-reference, but that's for macro programming.)

Or you can put the thing you want to change in a container:

Not:

 (defun frob (x)
   (setf x (+ x 1)))

 (let ((x 1))
   (frob x)
   x) ; => 1 -- sorry, no bonus

But:

 (defstruct box value)

 (defun frob-boxed (x)
   (setf (box-value x) (+ 1 (box-value x))))

 (let ((x (make-box :value 1)))
   (frob-boxed x)
   (box-value x)) ; 2 -- yay!

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."
From: Thomas Schilling
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <opsapwytuztrs3c0@news.CIS.DFN.DE>
neo88 <······@truevine.net> wrote:

> (defun stuff(anything)
>    (let &this_thing = (anything))
>        (print list(&this_thing)(anything)))
>
> I know that's a bit sloppy, and I'm not sure if the ouput is quite
> right, but what I'm trying to do is refrence a function to a list. Can
> it be done in a way similar to that?

For the Lisp-way of thinking I agree with the former posters. Now an 
attempt to interpret your question ;).

If you meant type-casts, then, again, this isn't possible in Lisp. 
Actually you don't need to. The type information is stored with(in) the 
object. So an object can never be treated as something it isn't. (In 
practice, you really don't need to.)

If you wanted to get the code of a function by casting it to a list this, 
doesn't work, too. Since the function object doesn't stand for the list of 
code. Indeed the code=data analogy is only conceptionally. In practice 
functions are compiled to machine code or to some intermediate code being 
executed on a virtual machine. To get the code of a function use 
(disassemble #'myfun).

Just in case you wanted to know that ;)

regards

-ts
-- 
      ,,
     \../   /  <<< The LISP Effect
    |_\\ _==__
__ | |bb|   | _________________________________________________
From: Kalle Olavi Niemitalo
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <87vfh1ysio.fsf@Astalo.kon.iki.fi>
Thomas Schilling <······@yahoo.de> writes:

> If you wanted to get the code of a function by casting it to a list
> this, doesn't work, too.

The opposite transformation (from a list to a function) is
somewhat cast-like, however:

(funcall (coerce '(lambda () (format t "~&Hello, world!~%")) 'function))

> To get the code of a function use (disassemble #'myfun).

Also (function-lambda-expression #'myfun), but that is not reliable.
From: Thomas Schilling
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <opsaqe7egetrs3c0@news.CIS.DFN.DE>
Replying to myself:

> If you meant type-casts, then, again, this isn't possible in Lisp. 
> Actually you don't need to. The type information is stored with(in) the 
> object. So an object can never be treated as something it isn't. (In 
> practice, you really don't need to.)

Actually I forgot to mention-- there's a way of a doing something similar 
like a cast: COERCE'ing.

But this is a saver than (static) casting since a casting only _treats_ 
things as something different while coercing really _makes_ it something 
different. (For further details, please see the HyperSpec.)
-- 
      ,,
     \../   /  <<< The LISP Effect
    |_\\ _==__
__ | |bb|   | _________________________________________________
From: Kenny Tilton
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <ApAGc.59436$a92.19375@twister.nyc.rr.com>
neo88 wrote:

> I am still a bit of a newbie to the Lisp paradigm, although I have
> been programming in it for a few months now, I still don't feel as
> comfortable with it as do other langauges like C++. I came aupon a
> question a few days ago, and can't seem to find the answer to it in
> any of the books or documentation I have about Lisp. The question is:
> Does Lisp a form of memory allocation?
> C has malloc(), C++ has the new and this pointer, etc. What about
> Lisp? I still haven't seen anything like that when I have been
> programming in it. The closest function I have seen to memory
> allocation is (setq). Does Lisp have anything similar to the pointers
> introduced by C++? How do you refrence an object in Lisp? Can you do
> something similar to the following:
> 
> (defun stuff(anything)
>    (let &this_thing = (anything))
>        (print list(&this_thing)(anything)))
> 
> I know that's a bit sloppy, ...

Not so much sloppy as "hard to understand". Lotsa folks here know C, so 
just post a snippet in straight C/C++ and we'll understand better.

Or post an example in Lisp which does not to your mind work like C/C++ 
and ask how it could be made to produce a specific result.

We have had Qs along this line such as:

"(defun one ()
   (let ((x 42))
       (two x)
       (eq x 24)))

(defun two (in-value)
    (setq in-value 24))

How can I get ONE to return t?"

Either way folks can help, but I at least cannot make out what your 
hybrid of Lisp and C is meant to do.

kt


-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407070530.5180daf8@posting.google.com>
Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> neo88 wrote:
> 
> > I am still a bit of a newbie to the Lisp paradigm, although I have
> > been programming in it for a few months now, I still don't feel as
> > comfortable with it as do other langauges like C++. I came aupon a
> > question a few days ago, and can't seem to find the answer to it in
> > any of the books or documentation I have about Lisp. The question is:
> > Does Lisp a form of memory allocation?
> > C has malloc(), C++ has the new and this pointer, etc. What about
> > Lisp? I still haven't seen anything like that when I have been
> > programming in it. The closest function I have seen to memory
> > allocation is (setq). Does Lisp have anything similar to the pointers
> > introduced by C++? How do you refrence an object in Lisp? Can you do
> > something similar to the following:
> > 
> > (defun stuff(anything)
> >    (let &this_thing = (anything))
> >        (print list(&this_thing)(anything)))
> > 
> > I know that's a bit sloppy, ...
> 
> Not so much sloppy as "hard to understand". Lotsa folks here know C, so 
> just post a snippet in straight C/C++ and we'll understand better.
> 
> Or post an example in Lisp which does not to your mind work like C/C++ 
> and ask how it could be made to produce a specific result.
> 
> We have had Qs along this line such as:
> 
> "(defun one ()
>    (let ((x 42))
>        (two x)
>        (eq x 24)))
> 
> (defun two (in-value)
>     (setq in-value 24))
> 
> How can I get ONE to return t?"
> 
> Either way folks can help, but I at least cannot make out what your 
> hybrid of Lisp and C is meant to do.
> 
> kt

Hmmm. Let's see if I have this right. Lisp has garbage collection, so
you don't need 'new' or 'delete' as you do in C++. Lisp provides
memory allocation implictly, similar, I think to the way Perl does,
right? For example, in Perl (sorry I write better perl than Lisp ;)
you could do this:

$thing = 0;
@array = $mystuff;
foreach (thing -> $mystuff) {
# iterate through each value
}
printf(thing);

That allows you to set an array that implicity sets memory allocation,
iterate through it, then print the values. Can you do something
similar to this in Lisp?
BTW, sorry it's taken me so long to respond, I'm using Google groups
:(

neo88
From: Kenny Tilton
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <oXTGc.60937$a92.54986@twister.nyc.rr.com>
neo88 wrote:
> Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> 
>>neo88 wrote:
>>
>>
>>>I am still a bit of a newbie to the Lisp paradigm, although I have
>>>been programming in it for a few months now, I still don't feel as
>>>comfortable with it as do other langauges like C++. I came aupon a
>>>question a few days ago, and can't seem to find the answer to it in
>>>any of the books or documentation I have about Lisp. The question is:
>>>Does Lisp a form of memory allocation?
>>>C has malloc(), C++ has the new and this pointer, etc. What about
>>>Lisp? I still haven't seen anything like that when I have been
>>>programming in it. The closest function I have seen to memory
>>>allocation is (setq). Does Lisp have anything similar to the pointers
>>>introduced by C++? How do you refrence an object in Lisp? Can you do
>>>something similar to the following:
>>>
>>>(defun stuff(anything)
>>>   (let &this_thing = (anything))
>>>       (print list(&this_thing)(anything)))
>>>
>>>I know that's a bit sloppy, ...
>>
>>Not so much sloppy as "hard to understand". Lotsa folks here know C, so 
>>just post a snippet in straight C/C++ and we'll understand better.
>>
>>Or post an example in Lisp which does not to your mind work like C/C++ 
>>and ask how it could be made to produce a specific result.
>>
>>We have had Qs along this line such as:
>>
>>"(defun one ()
>>   (let ((x 42))
>>       (two x)
>>       (eq x 24)))
>>
>>(defun two (in-value)
>>    (setq in-value 24))
>>
>>How can I get ONE to return t?"
>>
>>Either way folks can help, but I at least cannot make out what your 
>>hybrid of Lisp and C is meant to do.
>>
>>kt
> 
> 
> Hmmm. Let's see if I have this right. Lisp has garbage collection, so
> you don't need 'new' or 'delete' as you do in C++. Lisp provides
> memory allocation implictly, similar, I think to the way Perl does,
> right?

No. The allocation (new) is still explicit--try (apropos 'make-). The 
collection (delete) is automatic and transparent, tho a common extension 
is to offer a "finalize" callback which would give the user a chance to 
get involved with collection.

  For example, in Perl (sorry I write better perl than Lisp ;)

uh-oh. Perl is not only less well known than C/C++, it also prides 
itself on its unreadability, so I cannot even guess at what the 
following does or how it can possibly work. :) Others here will, however.

> you could do this:
> 
> $thing = 0;
> @array = $mystuff;
> foreach (thing -> $mystuff) {
> # iterate through each value
> }
> printf(thing);

Frightening. Someone please tell me that is shot thru with syntax errors!!!

:)

kt

-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407071341.70dbfbb9@posting.google.com>
Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> neo88 wrote:
> > Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> > 
> >>neo88 wrote:
> >>
> >>
> >>>I am still a bit of a newbie to the Lisp paradigm, although I have
> >>>been programming in it for a few months now, I still don't feel as
> >>>comfortable with it as do other langauges like C++. I came aupon a
> >>>question a few days ago, and can't seem to find the answer to it in
> >>>any of the books or documentation I have about Lisp. The question is:
> >>>Does Lisp a form of memory allocation?
> >>>C has malloc(), C++ has the new and this pointer, etc. What about
> >>>Lisp? I still haven't seen anything like that when I have been
> >>>programming in it. The closest function I have seen to memory
> >>>allocation is (setq). Does Lisp have anything similar to the pointers
> >>>introduced by C++? How do you refrence an object in Lisp? Can you do
> >>>something similar to the following:
> >>>
> >>>(defun stuff(anything)
> >>>   (let &this_thing = (anything))
> >>>       (print list(&this_thing)(anything)))
> >>>
> >>>I know that's a bit sloppy, ...
> >>
> >>Not so much sloppy as "hard to understand". Lotsa folks here know C, so 
> >>just post a snippet in straight C/C++ and we'll understand better.
> >>
> >>Or post an example in Lisp which does not to your mind work like C/C++ 
> >>and ask how it could be made to produce a specific result.
> >>
> >>We have had Qs along this line such as:
> >>
> >>"(defun one ()
> >>   (let ((x 42))
> >>       (two x)
> >>       (eq x 24)))
> >>
> >>(defun two (in-value)
> >>    (setq in-value 24))
> >>
> >>How can I get ONE to return t?"
> >>
> >>Either way folks can help, but I at least cannot make out what your 
> >>hybrid of Lisp and C is meant to do.
> >>
> >>kt
> > 
> > 
> > Hmmm. Let's see if I have this right. Lisp has garbage collection, so
> > you don't need 'new' or 'delete' as you do in C++. Lisp provides
> > memory allocation implictly, similar, I think to the way Perl does,
> > right?
> 
> No. The allocation (new) is still explicit--try (apropos 'make-). The 
> collection (delete) is automatic and transparent, tho a common extension 
> is to offer a "finalize" callback which would give the user a chance to 
> get involved with collection.
What do you mean by "automatic and transparent"? Automatic I think I
can understand, the garbage collector automaticly allocates memory for
the function or variable or whatever. It's the transparent that is
getting me....
and make- is the same thing as new? Sorry, I'm a bit slow, and I
really want to get this striaght. :)
> 

>   For example, in Perl (sorry I write better perl than Lisp ;)
> 
> uh-oh. Perl is not only less well known than C/C++, it also prides 
> itself on its unreadability, so I cannot even guess at what the 
> following does or how it can possibly work. :) Others here will, however.
> 
> > you could do this:
> > 
> > $thing = 0;
> > @array = $mystuff;
> > foreach (thing -> $mystuff) {
> > # iterate through each value
> > }
> > printf(thing);
> 
> Frightening. Someone please tell me that is shot thru with syntax errors!!!
lol. No it's not actually, sorry ;)
> 
> :)
> 

> kt
neo88
From: Kenny Tilton
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <ZJ0Hc.61001$a92.10002@twister.nyc.rr.com>
neo88 wrote:
> Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> 
>>neo88 wrote:
>>
>>>Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
>>>
>>>
>>>>neo88 wrote:
>>>>
>>>>
>>>>
>>>Hmmm. Let's see if I have this right. Lisp has garbage collection, so
>>>you don't need 'new' or 'delete' as you do in C++. Lisp provides
>>>memory allocation implictly, similar, I think to the way Perl does,
>>>right?
>>
>>No. The allocation (new) is still explicit--try (apropos 'make-). The 
>>collection (delete) is automatic and transparent, tho a common extension 
>>is to offer a "finalize" callback which would give the user a chance to 
>>get involved with collection.
> 
> What do you mean by "automatic and transparent"? Automatic I think I
> can understand, the garbage collector automaticly allocates memory...

you mean deallocates or frees, not "allocates", I hope.

anyway, do not worry about "transparent", I just wanted to drive home 
the point. A car has an automatic transmission, but I still choose 
between park, reverse, neutral, and a number of forward settings.

  for
> the function or variable or whatever. It's the transparent that is
> getting me....


> and make- is the same thing as new?

yeah. IIRC, in C++ I can allocate a temporary structure just by 
declaring a variable with the structure as its type (instead of the more 
usual structure pointer syntax). That structure gets deallocated when it 
goes out of scope. (pardon any mistaken jargon.) with Lisp I would have 
to code: (let ((a (make-array 10)))...) if I want to allocate a new 
array. [Aside: and then deallocation happens not when control leaves the 
dynamic scope of the let, but when the array is unreachable.]

Note that your orginal question was how to get a pointer, and in a sense 
(unless we are talking about numbers and characters and mebbe other 
things we need to be fast) the answer is "the only thing you /can/ get 
is a pointer".

 > Sorry, I'm a bit slow, and I
> really want to get this striaght. :)

There's your mistake. :) There is nothing to understand. Lisp is pretty 
painless. The thing to study up on is cons, car, and cdr so you can use 
the list data structure efficiently yet safely, consing neither too much 
nor too little. that can take a while to get down fluently.

kt

-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407080526.312be7e2@posting.google.com>
Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> neo88 wrote:
> > Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> > 
> >>neo88 wrote:
> >>
> >>>Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> >>>
> >>>
> >>>>neo88 wrote:
> >>>>
> >>>>
> >>>>
> >>>Hmmm. Let's see if I have this right. Lisp has garbage collection, so
> >>>you don't need 'new' or 'delete' as you do in C++. Lisp provides
> >>>memory allocation implictly, similar, I think to the way Perl does,
> >>>right?
> >>
> >>No. The allocation (new) is still explicit--try (apropos 'make-). The 
> >>collection (delete) is automatic and transparent, tho a common extension 
> >>is to offer a "finalize" callback which would give the user a chance to 
> >>get involved with collection.
> > 
> > What do you mean by "automatic and transparent"? Automatic I think I
> > can understand, the garbage collector automaticly allocates memory...
> 
> you mean deallocates or frees, not "allocates", I hope.
Yes, I meant "deallocates" there, can't you see the "de-" prefix :P
>
 
> anyway, do not worry about "transparent", I just wanted to drive home 
> the point. A car has an automatic transmission, but I still choose 
> between park, reverse, neutral, and a number of forward settings.
> 
>   for
> > the function or variable or whatever. It's the transparent that is
> > getting me....
> 
> 
> > and make- is the same thing as new?
> 
> yeah. IIRC, in C++ I can allocate a temporary structure just by 
> declaring a variable with the structure as its type (instead of the more 
> usual structure pointer syntax). That structure gets deallocated when it 
> goes out of scope. (pardon any mistaken jargon.) with Lisp I would have 
> to code: (let ((a (make-array 10)))...) if I want to allocate a new 
> array. [Aside: and then deallocation happens not when control leaves the 
> dynamic scope of the let, but when the array is unreachable.]
When does the array become unreachable? After it has been used it
scheduled time(s) in the program running it? I think in Java that the
memory is freed right after the variable goes out of lexial scope. So
it's not this way in Lisp? Can I see a log of the deallocation from
the garbage collector after the program is run? ie is there a keyword
for it like:
(show-contents-garbage)
or some such?
> 

> Note that your orginal question was how to get a pointer, and in a sense 
> (unless we are talking about numbers and characters and mebbe other 
> things we need to be fast) the answer is "the only thing you /can/ get 
> is a pointer".
That is very interesting. In this article here:
http://www.mactech.com/articles/mactech/Vol.07/07.05/LambdaCalculus/
there is a statement that goes something like this (can't find out
where it is in there exactly right now, I'm in a bit of a hurry):
We can return the pointer to
(if(combinator-false)
making (combinator-true) nil.
You should be able to find something similar to that in that article.
Now I know the article isn't about Lisp per se, but he is using Scheme
to do combinators in l-calculus. I suppose this is what you mean when
you say
"the only thing you /can/ get is a pointer"
could that be rewritten as
"the only structure returned /is/ a pointer"?


> 
>  > Sorry, I'm a bit slow, and I
> > really want to get this striaght. :)
> 
> There's your mistake. :) There is nothing to understand. Lisp is pretty 
> painless. The thing to study up on is cons, car, and cdr so you can use 
> the list data structure efficiently yet safely, consing neither too much 
> nor too little. that can take a while to get down fluently.
Nothing to understand?!?!?!?!?!?!?!?!?!?!? Maybe you're right, all
this just seems a wee bit strange to me right now though. I'm still
waiting for the light bulb to come on up here :)
You have any good links to resources about that kind of thing? I have
been reading the "Lisp Primer", and that is pretty good so far. I
think they assume you know how to cons, cdr, etc effictivly already
though. That is bad :(
> 
> kt
Thanks again for indulging a newbie to this whole thing :) :)
neo88
From: Paul Wallich
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <ccjnuc$jju$1@reader2.panix.com>
neo88 wrote:

> Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
> 
>>neo88 wrote:
>>
>>>Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
>>>
>>>
>>>>neo88 wrote:
>>>>
>>>>
>>>>>Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
>>>>>
>>>>>
>>>>>
>>>>>>neo88 wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>Hmmm. Let's see if I have this right. Lisp has garbage collection, so
>>>>>you don't need 'new' or 'delete' as you do in C++. Lisp provides
>>>>>memory allocation implictly, similar, I think to the way Perl does,
>>>>>right?
>>>>
>>>>No. The allocation (new) is still explicit--try (apropos 'make-). The 
>>>>collection (delete) is automatic and transparent, tho a common extension 
>>>>is to offer a "finalize" callback which would give the user a chance to 
>>>>get involved with collection.
>>>
>>>What do you mean by "automatic and transparent"? Automatic I think I
>>>can understand, the garbage collector automaticly allocates memory...
>>
>>you mean deallocates or frees, not "allocates", I hope.
> 
> Yes, I meant "deallocates" there, can't you see the "de-" prefix :P
> 
>  
> 
>>anyway, do not worry about "transparent", I just wanted to drive home 
>>the point. A car has an automatic transmission, but I still choose 
>>between park, reverse, neutral, and a number of forward settings.
>>
>>  for
>>
>>>the function or variable or whatever. It's the transparent that is
>>>getting me....
>>
>>
>>>and make- is the same thing as new?
>>
>>yeah. IIRC, in C++ I can allocate a temporary structure just by 
>>declaring a variable with the structure as its type (instead of the more 
>>usual structure pointer syntax). That structure gets deallocated when it 
>>goes out of scope. (pardon any mistaken jargon.) with Lisp I would have 
>>to code: (let ((a (make-array 10)))...) if I want to allocate a new 
>>array. [Aside: and then deallocation happens not when control leaves the 
>>dynamic scope of the let, but when the array is unreachable.]
> 
> When does the array become unreachable? After it has been used it
> scheduled time(s) in the program running it? I think in Java that the
> memory is freed right after the variable goes out of lexial scope. So
> it's not this way in Lisp? Can I see a log of the deallocation from
> the garbage collector after the program is run? ie is there a keyword
> for it like:
> (show-contents-garbage)
> or some such?

No, there isn't -- the whole point of some chunk of bits being garbage 
is that nothing in the live part of the system contains a reference to it.

>> > Sorry, I'm a bit slow, and I
>>
>>>really want to get this striaght. :)
>>
>>There's your mistake. :) There is nothing to understand. Lisp is pretty 
>>painless. The thing to study up on is cons, car, and cdr so you can use 
>>the list data structure efficiently yet safely, consing neither too much 
>>nor too little. that can take a while to get down fluently.
> 
> Nothing to understand?!?!?!?!?!?!?!?!?!?!? Maybe you're right, all
> this just seems a wee bit strange to me right now though. I'm still
> waiting for the light bulb to come on up here :)
> You have any good links to resources about that kind of thing? I have
> been reading the "Lisp Primer", and that is pretty good so far. I
> think they assume you know how to cons, cdr, etc effictivly already
> though. That is bad :(

The point Kenny is trying to pound in (which can be difficult for people 
coming from other languages to understand) is that _the system cleans up
your garbage for you_. Period. At this point in your learning of Lisp 
you don't have to know how or when, you hust have to know that as long 
as some part of your program is capable of referring to a given piece of 
data, that data will be there to refer to, and when all references are 
gone, that space will be available for putting more data into. Worrying 
about the details (until you become familiar with the rest of the 
languages) is like worrying about what happens inside the latch 
mechanism every time you turn a doorknob to open a door. Learn about 
lists and other data structures and how to put them together and look 
inside them for the bits you want, and don't worry about where they go 
when you're not using them any more. Your Lisp environmen will take care 
of that for you.

paul
From: ·········@random-state.net
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <ccjpdl$21rr6$2@midnight.cs.hut.fi>
Paul Wallich <··@panix.com> wrote:

>> the garbage collector after the program is run? ie is there a keyword
>> for it like:
>> (show-contents-garbage)
>> or some such?

> No, there isn't -- the whole point of some chunk of bits being garbage 
> is that nothing in the live part of the system contains a reference to it.

Though if you dip into implementation internals you may be able to
traverse the heap and figure out what is garbage and what isn't -- but
unless you're debugging the implementation's GC there is little reason to
do that.

Also, some implementations provide finalizers, so you can do something
like (using SBCL here):

 * (let ((x (cons t t)))
      (finalize x (lambda () (write-line "gone!")))
      'done)
 DONE
 * (gc)
 gone!
 NIL
 * 

[ Note: make sure your finalizer doesn't retain any references to the
  object being finalized: then it'll never be GC'd. ]

As others have said, the key is that you don't have to think about memory
allocation or deallocation: the system does it for you -- just trust it.

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."
From: Rob Warnock
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <PY2dnb3Sq9ngYXDd4p2dnA@speakeasy.net>
<·········@random-state.net> wrote:
+---------------
| Also, some implementations provide finalizers...
...
| [ Note: make sure your finalizer doesn't retain any references to the
|   object being finalized: then it'll never be GC'd. ]
+---------------

And in practice, this almost always means that you need another level
of indirection: the finalized object has to contain a pointer to the
"real" object you're worrying about, which the finalizer also contains
a pointer to (or is closed over, same thing). To extend your example:

    > (defmethod make-cleanup-thunk ((thing string))
	(lambda ()
	  (format t "The ~s has been cleaned up!~%" thing)))
    #<Standard-Method MAKE-CLEANUP-THUNK (STRING) {484C68A5}>
    > (let* ((x "Thing needing cleaning")
	     (y (list x)))
	(finalize y (make-cleanup-thunk x))
	'done)
    DONE
    > (gc)
    NIL
    > (gc)
    The "Thing needing cleaning" has been cleaned up!
    NIL
    >

[Note that it took two calls to GC in this case -- for no special
reason, just that the first one only needed to do a minor GC and
thus the finalized cons cell didn't get freed during the first one.]


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407090521.7d6d3ccc@posting.google.com>
····@rpw3.org (Rob Warnock) wrote in message news:<······················@speakeasy.net>...
> <·········@random-state.net> wrote:
> +---------------
> | Also, some implementations provide finalizers...
>  ...
> | [ Note: make sure your finalizer doesn't retain any references to the
> |   object being finalized: then it'll never be GC'd. ]
> +---------------
> 
> And in practice, this almost always means that you need another level
> of indirection: the finalized object has to contain a pointer to the
> "real" object you're worrying about, which the finalizer also contains
> a pointer to (or is closed over, same thing). To extend your example:
> 
>     > (defmethod make-cleanup-thunk ((thing string))
> 	(lambda ()
> 	  (format t "The ~s has been cleaned up!~%" thing)))
>     #<Standard-Method MAKE-CLEANUP-THUNK (STRING) {484C68A5}>
>     > (let* ((x "Thing needing cleaning")
> 	     (y (list x)))
> 	(finalize y (make-cleanup-thunk x))
> 	'done)
>     DONE
>     > (gc)
>  NIL
>     > (gc)
>     The "Thing needing cleaning" has been cleaned up!
>     NIL
>     >
> 
> [Note that it took two calls to GC in this case -- for no special
> reason, just that the first one only needed to do a minor GC and
> thus the finalized cons cell didn't get freed during the first one.]
> 
So, finialze and make-cleanup-thunk both call the GC? And yes I do
know what a thunk is :) Is there any other way to call the GC that I
should know about?
Thanks
neo88
> 
> -Rob
> 
> -----
> Rob Warnock			<····@rpw3.org>
> 627 26th Avenue			<URL:http://rpw3.org/>
> San Mateo, CA 94403		(650)572-2607
From: Rob Warnock
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <d5mdnSYzpq1VO3Ld4p2dnA@speakeasy.net>
neo88 <······@truevine.net> wrote:
+---------------
| ····@rpw3.org (Rob Warnock) wrote in message
| >     > (defmethod make-cleanup-thunk ((thing string))
| > 	(lambda ()
| > 	  (format t "The ~s has been cleaned up!~%" thing)))
| >     #<Standard-Method MAKE-CLEANUP-THUNK (STRING) {484C68A5}>
| >     > (let* ((x "Thing needing cleaning")
| > 	     (y (list x)))
| > 	(finalize y (make-cleanup-thunk x))
| > 	'done)
| >     DONE
| >     > (gc)
| >  NIL
| >     > (gc)
| >     The "Thing needing cleaning" has been cleaned up!
| >     NIL
| >     >
|
| So, finialze and make-cleanup-thunk both call the GC?
+---------------

Not sure what you mean by "call the GC". FINALIZE certainly leaves
some information *around* that the GC will use the next time it runs
(indeed, *every* time it runs until the finalized object is garbage),
but it certainly doesn't "call" the GC nor cause it to run.

And MAKE-CLEANUP-THUNK doesn't "call" the GC nor cause it to run, either.
It just does whatever to THING your application needed it to do when Y
became garbage.

+---------------
| Is there any other way to call the GC that I should know about?
+---------------

Rather than talking about "calling" the GC, it's probably better to
talk about under what circumstances the GC will run, basically for
only two or three reasons (depending on the style of GC): (1) When
the procedure named "GC" is called; (2) When an allocation is attempted
for which there is insufficient ready free memory available; (3) When
an allocation is attempted which causes some programmed trigger to
fire. As an example of the latter, CMUCL will run the GC whenever
EXT:*BYTES-CONSED-BETWEEN-GCS* bytes of memory have been allocated
since the last GC (default in CMUCL-18e is 12MB).

Except for debugging, tutorials (as above), and a few special cases
[e.g., preparing to dump a memory image], the procedure named "GC"
is never called in normal use, so reasons #2 & #3 are the main ones.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Kenny Tilton
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <8kdHc.61273$a92.45751@twister.nyc.rr.com>
neo88 wrote:
> Kenny Tilton <·······@nyc.rr.com> wrote in message news:<·····················@twister.nyc.rr.com>...
>>array. [Aside: and then deallocation happens not when control leaves the 
>>dynamic scope of the let, but when the array is unreachable.]
> 
> When does the array become unreachable?

Well, I am just an application programmer, but it goes a little bit like 
this: the garbage collector starts somewhere (globals and the stack?) 
and then recursively follows any references found marking everything. 
Whichever objects have been allocated but not marked are deemed to be 
unreachable and get collected. Note that if the only references to X are 
in unreachable objects, X is still unreachable and gets collected even 
tho references to it exist.

  After it has been used it
> scheduled time(s) in the program running it? I think in Java that the
> memory is freed right after the variable goes out of lexial scope.

Well, if you allocate a new Java object (x = new Thing;?) and pass it to 
other functions, Java cannot be sure it can be collected just because 
the program exits the scope of "x", so the memory is not freed until the 
next GC. What Lisp does not have is "Thing x;", which would indeed be freed.

Come to think of it, Java has GC, so Lisp should not be all that unfamiliar.

  So
> it's not this way in Lisp? Can I see a log of the deallocation from
> the garbage collector after the program is run? ie is there a keyword
> for it like:
> (show-contents-garbage)
> or some such?

Different Lisps would offer different hooks into the GC. Not sure what 
sorts of things are available. Like I said, it is not an issue. I just 
worry about not allocating objects unnecessarily.

> to do combinators in l-calculus. I suppose this is what you mean when
> you say
> "the only thing you /can/ get is a pointer"
> could that be rewritten as
> "the only structure returned /is/ a pointer"?

I guess. But I was talking about "xp = new Thing" vs "Thing x". In the 
case of C++, it makes sense to talk about taking the address of x so 
some other function can mutate it. That is how I understood your Q about 
"how do I get a pointer to..."? Lisp does not do "Thing x" as a way of 
allocating memory, so you never have to "get a pointer".

> Nothing to understand?!?!?!?!?!?!?!?!?!?!? Maybe you're right, all
> this just seems a wee bit strange to me right now though.

Why? (let ((x (make-widget))... is (for this purpose) like:

     x = (malloc (sizeof Widget));

or

     x = new Widget;

You seem familiar with those. The nice thing about "pointerless" 
(meaning you cannot take the address of something) languages such as 
Smalltalk and Lisp is that one does have two possibilities to keep 
straight ("is that a Thing or a pointer to a Thing?"). The irony is that 
this is done by making everything work like a pointer, except for things 
like numbers and characters.

kt

-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407081109.5753c7eb@posting.google.com>
> 
> > Nothing to understand?!?!?!?!?!?!?!?!?!?!? Maybe you're right, all
> > this just seems a wee bit strange to me right now though.
> 
> Why? (let ((x (make-widget))... is (for this purpose) like:
> 
>      x = (malloc (sizeof Widget));
> 
> or
> 
>      x = new Widget;
> 
> You seem familiar with those. The nice thing about "pointerless" 
> (meaning you cannot take the address of something) languages such as 
> Smalltalk and Lisp is that one does have two possibilities to keep 
> straight ("is that a Thing or a pointer to a Thing?"). The irony is that 
> this is done by making everything work like a pointer, except for things 
> like numbers and characters.
> 
I am familier with those. I think I understand a little better now :)
:)
In Lisp it only works like a pointer, but isn't really one. Right? If
that's the case, I think I am beginning to get it.
It's going to be weird not being able to take the address of something
though. I'll have to get used to that one. And just to clarify,
numbers and characters do NOT work like pointers?
Thanks, I think I'm finally getting it!
> kt
neo88
From: Paul Wallich
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <cck8gt$ps7$1@reader2.panix.com>
neo88 wrote:
>>>Nothing to understand?!?!?!?!?!?!?!?!?!?!? Maybe you're right, all
>>>this just seems a wee bit strange to me right now though.
>>
>>Why? (let ((x (make-widget))... is (for this purpose) like:
>>
>>     x = (malloc (sizeof Widget));
>>
>>or
>>
>>     x = new Widget;
>>
>>You seem familiar with those. The nice thing about "pointerless" 
>>(meaning you cannot take the address of something) languages such as 
>>Smalltalk and Lisp is that one does have two possibilities to keep 
>>straight ("is that a Thing or a pointer to a Thing?"). The irony is that 
>>this is done by making everything work like a pointer, except for things 
>>like numbers and characters.
>>
> 
> I am familier with those. I think I understand a little better now :)
> :)
> In Lisp it only works like a pointer, but isn't really one. Right? If
> that's the case, I think I am beginning to get it.
> It's going to be weird not being able to take the address of something
> though. I'll have to get used to that one.

Why would you want to take the address of something? Seriously, why?
If your language gives you tools to access it and all its components by 
name (or other symbolic form of reference), there's no need to know 
where in RAM it happens to reside at the moment. (And there's good 
reason not to know, because if you hold onto that address through a GC 
and the thing moves, you're hosed.)

> And just to clarify,
> numbers and characters do NOT work like pointers?
> Thanks, I think I'm finally getting it!

Numbers and characters don't work like pointers in the sense that 
they're not (generally) unique objects, so you can't do the shorthand of 
asking whether two of them are equal to another by seeing if they point 
to the same place (the EQ test).

paul
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407081753.320124d6@posting.google.com>
Paul Wallich <··@panix.com> wrote in message news:<············@reader2.panix.com>...
> neo88 wrote:
> >>>Nothing to understand?!?!?!?!?!?!?!?!?!?!? Maybe you're right, all
> >>>this just seems a wee bit strange to me right now though.
> >>
> >>Why? (let ((x (make-widget))... is (for this purpose) like:
> >>
> >>     x = (malloc (sizeof Widget));
> >>
> >>or
> >>
> >>     x = new Widget;
> >>
> >>You seem familiar with those. The nice thing about "pointerless" 
> >>(meaning you cannot take the address of something) languages such as 
> >>Smalltalk and Lisp is that one does have two possibilities to keep 
> >>straight ("is that a Thing or a pointer to a Thing?"). The irony is that 
> >>this is done by making everything work like a pointer, except for things 
> >>like numbers and characters.
> >>
> > 
> > I am familier with those. I think I understand a little better now :)
> > :)
> > In Lisp it only works like a pointer, but isn't really one. Right? If
> > that's the case, I think I am beginning to get it.
> > It's going to be weird not being able to take the address of something
> > though. I'll have to get used to that one.
> 
> Why would you want to take the address of something? Seriously, why?
> If your language gives you tools to access it and all its components by 
> name (or other symbolic form of reference), there's no need to know 
> where in RAM it happens to reside at the moment. (And there's good 
> reason not to know, because if you hold onto that address through a GC 
> and the thing moves, you're hosed.)
> 
That's a good point, I never really thought about that before, I'm
just so used to doing it, it's just second nature for me I guess :)
Breaking the habit now though :) So since Lisp provides a symbolic way
to refrence objects, so I don't need to know where they are, then the
GC takes care of the rest. I really like that!
> > And just to clarify,
> > numbers and characters do NOT work like pointers?
> > Thanks, I think I'm finally getting it!
> 
> Numbers and characters don't work like pointers in the sense that 
> they're not (generally) unique objects, so you can't do the shorthand of 
> asking whether two of them are equal to another by seeing if they point 
> to the same place (the EQ test).
> 
Ok, gotcha
> paul
neo88
From: Jock Cooper
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <m3pt75t71a.fsf@jcooper02.sagepub.com>
······@truevine.net (neo88) writes:
> That's a good point, I never really thought about that before, I'm
> just so used to doing it, it's just second nature for me I guess :)
> Breaking the habit now though :) So since Lisp provides a symbolic way
> to refrence objects, so I don't need to know where they are, then the

I know where you are coming from, I had a C background and felt very
much like I needed to have pointers to get anything done.  In my
attempt to design "high entropy" code (ie low code duplication) I
used to do a lot of really sophistocated things with things like
arrays of pointer to functions returning arrays of pointer to function
and so on.

Believe me, you will not miss that in Common Lisp.  Compared to CL,
C's malloc,free,&,*,[],.,-> and all that horrible syntax feels like
trying to build a boat in a bottle with long skinny tools.
From: Joe Marshall
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <r7rlqay7.fsf@ccs.neu.edu>
Jock Cooper <·····@mail.com> writes:

> Compared to CL, C's malloc,free,&,*,[],.,-> and all that horrible
> syntax feels like trying to build a boat in a bottle with long
> skinny tools.

Hmm.  To me it always felt like trying to build a boat in a bottle
with short, fat tools.
From: Kenny Tilton
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <NKXHc.38333$4h7.4094304@twister.nyc.rr.com>
Jock Cooper wrote:

> ······@truevine.net (neo88) writes:
> 
>>That's a good point, I never really thought about that before, I'm
>>just so used to doing it, it's just second nature for me I guess :)
>>Breaking the habit now though :) So since Lisp provides a symbolic way
>>to refrence objects, so I don't need to know where they are, then the
> 
> 
> I know where you are coming from, I had a C background and felt very
> much like I needed to have pointers to get anything done.  In my
> attempt to design "high entropy" code (ie low code duplication) I
> used to do a lot of really sophistocated things with things like
> arrays of pointer to functions returning arrays of pointer to function
> and so on.
> 
> Believe me, you will not miss that in Common Lisp.  Compared to CL,
> C's malloc,free,&,*,[],.,-> and all that horrible syntax feels like
> trying to build a boat in a bottle with long skinny tools.

Congrats, that's the first non-Road highlight (last entry under "The 
Pragmatists"):

  http://alu.cliki.net/RtL%20Highlight%20Film

kt

-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: Rob Warnock
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <gNqdnZhugej5anDd4p2dnA@speakeasy.net>
Paul Wallich  <··@panix.com> wrote:
+---------------
| neo88 wrote:
| > And just to clarify, numbers and characters do NOT work like pointers?
|
| Numbers and characters don't work like pointers in the sense that
| they're not (generally) unique objects, so you can't do the shorthand
| of asking whether two of them are equal to another by seeing if they
| point to the same place (the EQ test).
+---------------

But on the other hand, you can never be sure that they *aren't* pointers,
either. Both bignums (anything bigger than MOST-POSITIVE-FIXNUM) and
"fat" characters (if your implementation supports them) might very well
be heap-allocated.[1]

When explaining this to newcomers, I find it easier to simply say that
in Lisp *everything* is a pointer[2], except that the implementation
is allowed to optimize the representation of some objects by encoding
them as "funny" or "immediate" pointers.


-Rob

[1] The original SIOD implementation of R3RS Scheme (later used in
    The GIMP as an extension language) represented *all* numbers
    as heap-allocated C "doubles", but lessened the strain on the
    allocator by consing a small range of whole numbers (typically
    -100.0 through 1000.0) at startup time. Numeric functions did
    a quick range check on their results and returned one of the
    preallocated numbers if possible.

[2] Though this really bothers some purists [search Google Groups for
    "everything is a pointer"] who would prefer to say "everything is
    an object" and then mumble something about usually never needing
    to know whether the representation of an object is a pointer to
    a hunk of heap or an immediate pointer-like cookie (or even an
    unboxed native machine type).

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Edi Weitz
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <87acybj1t7.fsf@bird.agharta.de>
On Wed, 07 Jul 2004 14:40:20 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:

> neo88 wrote:
>
>   For example, in Perl (sorry I write better perl than Lisp ;)
>
> uh-oh. Perl is not only less well known than C/C++,

I doubt that.

> it also prides itself on its unreadability, so I cannot even guess
> at what the following does or how it can possibly work. :) Others
> here will, however.
>
>> you could do this:
>> $thing = 0;
>> @array = $mystuff;
>> foreach (thing -> $mystuff) {
>> # iterate through each value
>> }
>> printf(thing);
>
> Frightening. Someone please tell me that is shot thru with syntax
> errors!!!

It's hard to convince Perl that something is a syntax error because it
tries hard to "do the right thing" (and very often fails at that
IMHO). The code above returns "syntax OK" if you test with "perl -c"
but it certainly is full of things that are, well, strange:

1. The line

     @array = $mystuff;

   will make @array an array which one element, namely the scalar
   $mystuff. Most people will probably write

     @array = ($mystuff);

   instead.

2. And

     foreach (thing -> $mystuff)

   will generate an error like

     Can't locate object method "" via package "thing"

   at runtime. If you replace 'thing' with '$thing' you get

     Use of uninitialized value in method lookup

   at runtime (and still "syntax OK" before that). "->" is the Perl
   syntax for getting at object methods, it has nothing to do with
   foreach.

3. Perhaps he meant

     foreach $thing ($mystuff)

   which would be kind of correct but again would implicitely coerce
   the scalar $mystuff into a one-element array. The canonical syntax
   would be

     foreach $thing (($mystuff))

   where the outer parentheses are syntactical markers required by
   foreach and the inner ones are there to denote the array. (Who said
   Lisp has too much of them?)

4. Finally,

     printf(thing)

   will interpret 'thing' as a filehandle - try to run this with
   warnings enabled. If he meant

     printf($thing)

   this is a little bit better but won't print $thing correctly if
   it's a string containing control sequences which would be
   interpreted by printf.

Sigh...

Edi.

-- 

"Lisp doesn't look any deader than usual to me."
(David Thornley, reply to a question older than most languages)

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407071637.5b6aca5a@posting.google.com>
Edi Weitz <········@agharta.de> wrote in message news:<··············@bird.agharta.de>...
> On Wed, 07 Jul 2004 14:40:20 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:
> 
> > neo88 wrote:
> >
> >   For example, in Perl (sorry I write better perl than Lisp ;)
> >
> > uh-oh. Perl is not only less well known than C/C++,
> 
> I doubt that.
> 
> > it also prides itself on its unreadability, so I cannot even guess
> > at what the following does or how it can possibly work. :) Others
> > here will, however.
> >
> >> you could do this:
> >> $thing = 0;
> >> @array = $mystuff;
> >> foreach (thing -> $mystuff) {
> >> # iterate through each value
> >> }
> >> printf(thing);
> >
> > Frightening. Someone please tell me that is shot thru with syntax
> > errors!!!
> 
> It's hard to convince Perl that something is a syntax error because it
> tries hard to "do the right thing" (and very often fails at that
> IMHO). The code above returns "syntax OK" if you test with "perl -c"
> but it certainly is full of things that are, well, strange:
> 
> 1. The line
> 
>      @array = $mystuff;
> 
>    will make @array an array which one element, namely the scalar
>    $mystuff. Most people will probably write
> 
>      @array = ($mystuff);
> 
>    instead.
> 
> 2. And
> 
>      foreach (thing -> $mystuff)
> 
>    will generate an error like
> 
>      Can't locate object method "" via package "thing"
> 
>    at runtime. If you replace 'thing' with '$thing' you get
> 
>      Use of uninitialized value in method lookup
> 
>    at runtime (and still "syntax OK" before that). "->" is the Perl
>    syntax for getting at object methods, it has nothing to do with
>    foreach.
> 
What version of Perl are you running? $thing is initialzed as 
$thing = 0;
in the first line of this little program.
> 3. Perhaps he meant
> 
>      foreach $thing ($mystuff)
> 
>    which would be kind of correct but again would implicitely coerce
>    the scalar $mystuff into a one-element array. The canonical syntax
>    would be
> 
>      foreach $thing (($mystuff))
That's what I meant to say:
foreach $thing (($mystuff))
Sorry, wrote that in a hurry, was at the end of lunch break. :)
> 

>    where the outer parentheses are syntactical markers required by
>    foreach and the inner ones are there to denote the array. (Who said
>    Lisp has too much of them?)
> 
> 4. Finally,
> 
>      printf(thing)
> 
>    will interpret 'thing' as a filehandle - try to run this with
>    warnings enabled. If he meant
> 
>      printf($thing)
> 
>    this is a little bit better but won't print $thing correctly if
>    it's a string containing control sequences which would be
>    interpreted by printf.
Ahhh, but it's not.
> 
Didn't mean to get too OT :) Ah well, since I'm using google, it'll be
another three hours before I see this up there with any responses....
I think I already mentioned that in this thread though :)
Back to Memory Allocation in Lisp!!!!!!!!
> Sigh...
> 
> Edi.

neo88
From: Pascal Costanza
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <cch10v$qas$1@f1node01.rhrz.uni-bonn.de>
neo88 wrote:

> Hmmm. Let's see if I have this right. Lisp has garbage collection, so
> you don't need 'new' or 'delete' as you do in C++. Lisp provides
> memory allocation implictly, similar, I think to the way Perl does,
> right? For example, in Perl (sorry I write better perl than Lisp ;)
> you could do this:
> 
> $thing = 0;
> @array = $mystuff;
> foreach (thing -> $mystuff) {
> # iterate through each value
> }
> printf(thing);
> 
> That allows you to set an array that implicity sets memory allocation,
> iterate through it, then print the values. Can you do something
> similar to this in Lisp?

(let ((thing 0)
       (array mystuff))
   (loop for thing across mystuff
         do (something thing))
   (print thing))

...or some such.

Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)
From: Iain Little
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <873c4547gi.fsf@yahoo.com>
······@truevine.net (neo88) writes:

> I am still a bit of a newbie to the Lisp paradigm, although I have
> been programming in it for a few months now, I still don't feel as
> comfortable with it as do other langauges like C++. I came aupon a
> question a few days ago, and can't seem to find the answer to it in
> any of the books or documentation I have about Lisp. The question is:
> Does Lisp a form of memory allocation?

Common Lisp doesn't have any standard way of explicitly allocating
memory, and then fiddling with pointers.  Part of what is nice about
Lisp is that you don't have to worry about that stuff.  But if what
you really mean is how do you create new objects, then that depends on
what you want to create.  LIST will create a new list, CONS will
create a new cons cell, MAKE-ARRAY will create a new array,
MAKE-INSTANCE will create a new instance of a class, etc.

> C has malloc(), C++ has the new and this pointer, etc. What about
> Lisp? I still haven't seen anything like that when I have been
> programming in it. The closest function I have seen to memory
> allocation is (setq). Does Lisp have anything similar to the pointers
> introduced by C++? How do you refrence an object in Lisp? Can you do
> something similar to the following:

In Common Lisp, every object is considered to be a value, and you can
pass it around the same way you would an integer or whatever.  You
don't need to go to the trouble of finding out the address of an
object, passing around that address, and then telling the compiler
that you want to treat this address as a function or whatever.  Just
treat the function as you would an integer, and you will probably get
what you want.

> (defun stuff(anything)
>    (let &this_thing = (anything))
>        (print list(&this_thing)(anything)))

I'm not sure what you are trying to do here.  If you are trying to
create a contains the contents of `anything', then you do that like
this:

(defun foo (anything)
  (list anything))

(foo 42) ==> '(42)

But maybe the following example might help more:

(defun bar (function anything)
  (funcall function anything))

(bar #'list 5) ==> '(5)

(defun halve (x) 
  (/ x 2))

(halve 4) ==> 2
(bar #'halve 4) ==> 2

(bar #'(lambda (x) (+ x 42)) 8) ==> 50

To learn Lisp properly you need to forget about memory locations and
pointers and start thinking in terms of objects and values.

Cheers,


Iain
From: neo88
Subject: Re: Memory Allocation in Lisp?
Date: 
Message-ID: <6a73bb68.0407101418.582dbe4a@posting.google.com>
······@truevine.net (neo88) wrote in message news:<····························@posting.google.com>...
> I am still a bit of a newbie to the Lisp paradigm, although I have
> been programming in it for a few months now, I still don't feel as
> comfortable with it as do other langauges like C++. I came aupon a
> question a few days ago, and can't seem to find the answer to it in
> any of the books or documentation I have about Lisp. The question is:
> Does Lisp a form of memory allocation?
> C has malloc(), C++ has the new and this pointer, etc. What about
> Lisp? I still haven't seen anything like that when I have been
> programming in it. The closest function I have seen to memory
> allocation is (setq). Does Lisp have anything similar to the pointers
> introduced by C++? How do you refrence an object in Lisp? Can you do
> something similar to the following:
> 
> (defun stuff(anything)
>    (let &this_thing = (anything))
>        (print list(&this_thing)(anything)))
> 
> I know that's a bit sloppy, and I'm not sure if the ouput is quite
> right, but what I'm trying to do is refrence a function to a list. Can
> it be done in a way similar to that?
> I apologize if I have overloaded you guys with questions, I just
> couldn't find anything about this in any of the resources that I have.
> Thanks for any answers.
> 
> neo88

I just recently (today) read this in "Common Lisp Programming for
Artificial Intelligence":

As far as Lisp is concerned the name of a variable 'means' some
location in the computers memory (the location where the variable is
stored and which holds a 'pointer' to the place where it's value is
stored)....

So that's why you don't need to explicitly get a pointer right? I get
it now!
About time, if I don't say so myself ;)
neo88
PS Thanks for all of the help everyone!