From: Ricardo Pereira
Subject: [Newbie] How the command cons works?
Date: 
Message-ID: <1038174950.304676@newsfront2>
Hello everyone,

I'm a experienced programmer but I just started learning Common Lisp very
recently. I would like to know how the cons command works, in technical
terms if possible.

Thank you for your attention!!

________________
:: Ricardo Pereira

From: Thomas F. Burdick
Subject: Re: [Newbie] How the command cons works?
Date: 
Message-ID: <xcvbs46nba9.fsf@apocalypse.OCF.Berkeley.EDU>
"Ricardo Pereira" <·······@hydra-soft.org> writes:

> Hello everyone,
> 
> I'm a experienced programmer but I just started learning Common Lisp very
> recently. I would like to know how the cons command works, in technical
> terms if possible.

It's a function that creates a cons cell.  What exactly a cons cell
is, is left up to the implementation.  Generally, it's a primitive
function, that creates a special type of object consisting of a type
tag saying it's a cons cell, and two pointers.  Here's a possible,
brain-damaged user-level implementation:

  (defun cons (car cdr)
    (lambda (command)
      (cond
        ((eql command 'car) car)
        ((eql command 'cdr) cdr)
        ((eql command 'type-of) 'cons)
        (t (error "Unknown command given to cons-cell")))))

  (defun car (cons)
    (funcall cons 'car))

  (defun cdr (cons)
    (funcall cons 'cdr))

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Chris Gehlker
Subject: Re: [Newbie] How the command cons works?
Date: 
Message-ID: <BA0E5B43.23DEC%gehlker@fastq.com>
On 11/24/02 3:04 PM, in article ·················@newsfront2, "Ricardo
Pereira" <·······@hydra-soft.org> wrote:

> Hello everyone,
> 
> I'm a experienced programmer but I just started learning Common Lisp very
> recently. I would like to know how the cons command works, in technical
> terms if possible.

Well, I'm a newbie, myself, but try this:

A cons or "cons cell" is an object like

Class cons {
   id car;
   id cdr;
};

The function (cons x y) is then like:

[[cons alloc] initWithCar: x Cdr:y]  - ObjC
Or
Cons.new(x, y) - Ruby
Or
new Cons(x, y) - C++

Lisp displays conses like (x . y) unless every cdr is either a reference to
another cons or nil. In that case, it displays the whole chain in "proper
list" form. Car and cdr can also be called "first" and "rest" to emphasize
the way conses are used to build linked lists.

Hope that helps.



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Henrik Motakef
Subject: Re: [Newbie] How the command cons works?
Date: 
Message-ID: <87wumu6f00.fsf@pokey.henrik-motakef.de>
"Ricardo Pereira" <·······@hydra-soft.org> writes:

> I'm a experienced programmer but I just started learning Common Lisp very
> recently. I would like to know how the cons command works, in technical
> terms if possible.

Are

| Function CONS
| 
| Syntax:
|  cons object-1 object-2 => cons
| 
| Arguments and Values:
|  object-1---an object.
|  object-2---an object.
|  cons---a cons.
| 
| Description:
|  Creates a fresh cons, the car of which is object-1 and the cdr of
|  which is object-2.

and

| System Class CONS
| 
| Class Precedence List:
|  cons, list, sequence, t
| 
| Description:
|  A cons is a compound object having two components, called the car
|  and cdr. These form a dotted pair. Each component can be any
|  object. 

technical enough? 
<http://www.lispworks.com/reference/HyperSpec/Body/a_cons.htm>

Regards
Henrik