f



Newbie question; why (cons (list 1 2) (list 3 4)) is ((1 2) 3 4) and not ((1 2) (3 4))

Hi,

I just started to learn LISP, and stumbled in SICP upon 
                                   
(cons (list 1 2) (list 3 4))

is evaluated to  

((1 2) 3 4) 

I do not understand why this is not: 

((1 2) (3 4))

because 

(cdr (cons (list 1 2) (list 3 4)))

is 

(3 4)

and 

(car (cons (list 1 2) (list 3 4)))

is

(1 2)

Is there a logical explanation?

Thank you for your patience.

--
Greg
0
3/25/2013 8:15:03 PM
comp.lang.lisp 16861 articles. 5 followers. Post Follow

17 Replies
4753 Views

Similar Articles

[PageSpeed] 39

Out of order, 

gregor <gregor@ediwo.com> writes:

> Is there a logical explanation?

Yes.

> I just started to learn LISP, and stumbled in SICP upon 

But first, let's talk about LISP, Lisp, Scheme and Common Lisp.

LISP is the name of the programming language invented in 1959 by John
McCarthy and of the first program implementing it written amongst other
by Steve Russel, one of his students.

LISP 1.5 is a segueing version of that same program dating about 1962
that had some distribution.

Then various lisp languages were developed at various places by various
teams.  Names such as MacLisp, InterLisp, LeLisp, StandardLisp, vLisp,
Lisp Machine Lisp, Scheme, GNU Emacs Lisp, etc.  It was quite a mess,
and people had a hard time sharing programs.  So they talked and
designed and wrote and voted and produced the ANSI Common Lisp standard
(in the USA), meanwhile in Europe they produced the ISO Lisp standard.

Nowadays, almost all the other lisps are "dead", with only scheme
(current version r5rs, r7rs being standardized), GNU emacs lisp, and
ANSI Common Lisp being widely used.



Now if you want to learn LISP, then I would point you to 
http://www.softwarepreservation.org/projects/LISP/lisp15_family/
You can download the sources and an emulator, have a look at:
http://www.mcjones.org/dustydecks/archives/2006/08/14/56/
I've put up my sources on gitorious:
https://gitorious.org/lisp-1-5/lisp-1-5

But notice that while SICP teaches the principles of computer science,
it uses scheme for its examples, and there are a lot of ideas and code
examples that cannot be implemented easily in LISP 1.5, since this later
lacks lexical bindings and closures (a famous bug in the original LISP
language design).  To learn about scheme learning resources you'd better
ask on news:comp.lang.scheme or try http://www.schemers.org/

Finally, since you're asking on  news:comp.lang.lisp, perhaps you want
to learn Common Lisp, which is certainly the best option if you want to
use lisp professionaly IMO.  Check http://cliki.net/ which has all the
pointers toward educational resources, implementations, libraries, etc,
about Common Lisp.


> (cons (list 1 2) (list 3 4))
>
> is evaluated to  
>
> ((1 2) 3 4) 
>
> I do not understand why this is not: 
>
> ((1 2) (3 4))
>
> because 
>
> (cdr (cons (list 1 2) (list 3 4)))
>
> is 
>
> (3 4)
>
> and 
>
> (car (cons (list 1 2) (list 3 4)))
>
> is
>
> (1 2)

As this is a Common Lisp oriented forum, I will assume you've installed
a Common Lisp implementation, and quicklisp 

http://www.cliki.net/Getting%20Started

so you can type at the REPL things like that:

cl-user> (ql:quickload :com.informatimago.common-lisp.picture)
To load "com.informatimago.common-lisp.picture":
  Load 1 ASDF system:
    com.informatimago.common-lisp.picture
; Loading "com.informatimago.common-lisp.picture"

(:com.informatimago.common-lisp.picture)
cl-user> (com.informatimago.common-lisp.picture.cons-to-ascii:draw-list (cons (list 1 2) (list 3 4)))
+-----------------------------------+
| ((1 2) 3 4)                       |
|                                   |
| +---+---+   +---+---+   +---+---+ |
| | * | * |-->| * | * |-->| * |NIL| |
| +---+---+   +---+---+   +---+---+ |
|   |           |           |       |
|   |           v           v       |
|   |         +---+       +---+     |
|   |         | 3 |       | 4 |     |
|   |         +---+       +---+     |
|   v                               |
| +---+---+   +---+---+             |
| | * | * |-->| * |NIL|             |
| +---+---+   +---+---+             |
|   |           |                   |
|   v           v                   |
| +---+       +---+                 |
| | 1 |       | 2 |                 |
| +---+       +---+                 |
+-----------------------------------+

cl-user> (com.informatimago.common-lisp.picture.cons-to-ascii:draw-list (list (list 1 2) 3 4))
+-----------------------------------+
| ((1 2) 3 4)                       |
|                                   |
| +---+---+   +---+---+   +---+---+ |
| | * | * |-->| * | * |-->| * |NIL| |
| +---+---+   +---+---+   +---+---+ |
|   |           |           |       |
|   |           v           v       |
|   |         +---+       +---+     |
|   |         | 3 |       | 4 |     |
|   |         +---+       +---+     |
|   v                               |
| +---+---+   +---+---+             |
| | * | * |-->| * |NIL|             |
| +---+---+   +---+---+             |
|   |           |                   |
|   v           v                   |
| +---+       +---+                 |
| | 1 |       | 2 |                 |
| +---+       +---+                 |
+-----------------------------------+

and comparing the cons cells obtained by 
both (list (list 1 2) 3 4)
and  (cons (list 1 2) (list 3 4))
you may be striken by the fact that they both produce the same cons cell
tree.

You could experiment with other expressions such as:

(list)
(list 1)
(cons 1 (list))
(list 1 2)
(cons 1 (cons 2 (list)))



The basic building block here is the cons cell:

cl-user> (com.informatimago.common-lisp.picture.cons-to-ascii:draw-list (cons  nil nil))
+-----------+
| (nil)     |
|           |
| +---+---+ |
| |NIL|NIL| |
| +---+---+ |
+-----------+

It has two slots (here they "empty" so we fill them with NIL).  

   Notice that in later scheme revisions, there's no nil variable
   defined, so you need to define it yourself if you're using scheme:
      (define nil '())
   But not if you're using Common Lisp.


In Common Lisp, nil is used to represent the empty list.  So when CL
sees (), it reads actually the symbol CL:NIL.

   In Scheme, () is THE empty list object, if you want a variable named
   nil, you have to define it yourself.


Then, in all lisps, lists are built from cons cells by chaining them in
their cdr slot, and storing the elements in their car cells:


    (cons 1 (cons 2 (cons 3 (list)))) ; I use (list) here to get the
                                      ; empty list, be it NIL or ().


cl-user> (com.informatimago.common-lisp.picture.cons-to-ascii:draw-list (cons 1 (cons 2 (cons 3 (list)))))
+-----------------------------------+
| (1 2 3)                           |
|                                   |
| +---+---+   +---+---+   +---+---+ |
| | * | * |-->| * | * |-->| * |NIL| |
| +---+---+   +---+---+   +---+---+ |
|   |           |           |       |
|   v           v           v       |
| +---+       +---+       +---+     |
| | 1 |       | 2 |       | 3 |     |
| +---+       +---+       +---+     |
+-----------------------------------+


That is, a proper list is either the empty list, or a cons cell whose
car slot contains an element, and whose cdr slot contains the rest of
the list (a proper list).  

With cons cells you can build other kind of structures, like trees,
records, graphs, or "improper" lists, such as dotted lists or circular
lists.

Dotted lists are lists whose last cons cell cdr slot contains another
atom than the empty list atom.  Atoms are any non-cons cell lisp object.

  Originally, cons cells were the only aggregate LISP object, hence the
  name atom for the other lisp objects (numbers or symbols, that's all
  there was; no strings, they used symbols to represent them).  Then
  strings and arrays and structures and objects and a lot of other
  aggregate object types were added, but they're all considered to be
  atoms, since they're all non-cons cells.  But they're not atomic, just
  like in physics, where atoms were thought to be atomic once, but then
  were split into nucleus and electrons, and then the nucleus into
  nucleons, and then nucleons into quarks, and then quarks into muons
  gluons etc and then into string oh well, it's turtles all the way
  down.


Ah yes, we call them dotted lists, because a cons cell is printed with a
dot between the car slot and the cdr slot:

   (cons 1 2) --> (1 . 2)

so a chain of cons cells that ends in a non-list cons cell is printed
with this dot before the contents of the last cdr slot:

  (cons 1 (cons 2 (cons 3 4))) --> (1 2 3 . 4) ; hence dotted-list.

Proper lists are of course printed simply as:

  (cons 1 (cons 2 (cons 3 (list)))) --> (1 2 3)
  (list 1 2 3)                      --> (1 2 3) ; of course you can use
                                                ; the list function to
                                                ; build proper lists
                                                ; with chains of cons
                                                ; cells.

Now you see the problem I hope.  When you have a cons cell that contains
a cons cell in its cdr slot, the lisp printer cannot fathom it's a cons
cell, but assumes instead that it's a list.  Therefore instead of
printing:

   ((1 2) . (3 4))

it prints:

   ((1 2) 3 4)

but this is exactly the same cons cell structure in memory.  It's just
that they are two equivalent printed representations.  There are more
printed representations for the same cons tree:

   ((1 . (2 . ())) . (3 . (4 . ())))
   ((1 . (2)) . (3 . (4))))
   ((1 2) 3 . (4))

and other combinations.


Notice also that all those printed representations are readable (but not
evaluable, since their first element is not an operator).  You can read
them back using the (read) function and then entering, or using the
QUOTE special operator to prevent their evaluation:


   (quote ((1 . (2 . ())) . (3 . (4 . ())))) --> ((1 2) 3 4)
   (quote ((1 . (2)) . (3 . (4))))           --> ((1 2) 3 4)
   (quote ((1 2) 3 . (4)))                   --> ((1 2) 3 4)
   (quote ((1 2) . (3 4)))                   --> ((1 2) 3 4)
   (quote ((1 2) 3 4))                       --> ((1 2) 3 4)


You may also use a different printer than the lisp printer.  For
example, print-conses, which will always print cons cells in their
dotted form:

    cl-user> (com.informatimago.common-lisp.picture.cons-to-ascii:print-conses '((1 2) . (3 4)))
    ((1  . (2  . ())) . (3  . (4  . ())))
    ((1 2) 3 4) ; and then the REPL prints the result which is the argument…

https://gitorious.org/com-informatimago/com-informatimago/blobs/master/common-lisp/picture/cons-to-ascii.lisp#line374


But you're right, perhaps we shouldn't trust the lisp printer (well, we
can usually, but there are some options (cf. the various *print-…*
variables in Common Lisp that may change its behavior)), so to be sure,
we can use car and cdr to check the tree ourselves.

;; refer to the diagrams above for ((1 2) . (3 4))

(defun check-my-tree (tree) 
   (and (consp tree)
        (consp (car tree))
        (eql 1 (car (car tree)))
        (consp (cdr (car tree)))
        (eql 2 (car (cdr (car tree))))
        (null (cdr (cdr (car tree))))
        (consp (cdr tree))
        (eql 3 (car (cdr tree)))
        (consp (cdr (cdr tree)))
        (eql 4 (car (cdr (cdr tree))))
        (null (cdr (cdr (cdr tree))))))

(mapcar (function check-my-tree)
        (quote (
                ((1 2) . (3 4))
                ((1 2) 3 4)
                ((1 . (2 . ())) . (3 . (4 . ())))
                ((1 . (2)) . (3 . (4)))
                ((1 2) 3 . (4))
                )))
--> (t t t t t) ; happy!



    (If you want to use scheme, it's slightly different:

        (define (check-my-tree tree) 
           (and (pair? tree)
                (pair? (car tree))
                (eqv? 1 (car (car tree)))
                (pair? (cdr (car tree)))
                (eqv? 2 (car (cdr (car tree))))
                (null? (cdr (cdr (car tree))))
                (pair? (cdr tree))
                (eqv? 3 (car (cdr tree)))
                (pair? (cdr (cdr tree)))
                (eqv? 4 (car (cdr (cdr tree))))
                (null? (cdr (cdr (cdr tree))))))

    of course, once you know how to program in scheme, you can also define
    functions and macros so that the above defun form does the same thing:

        (define (nullp x) (null? x))
        (define (consp x) (pair? x))
        etc…
    )
-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.
0
pjb (7869)
3/25/2013 9:40:02 PM
On Monday, March 25, 2013 2:40:02 PM UTC-7, informatimago wrote:
  ...

Bravo, Pascal!
0
taruss (74)
3/25/2013 10:29:27 PM
Hello Pascal,

Am Mon, 25 Mar 2013 22:40:02 +0100
schrieb "Pascal J. Bourguignon" <pjb@informatimago.com>:

> gregor <gregor@ediwo.com> writes:
>=20
> > Is there a logical explanation?
>=20
> Yes.

First of all let me say that I am astonished.
I can't remember that I got such a detailed answer anywhere on the
internet using it for 20 years now.
Thank you for the time you took to help me.

>=20
> > I just started to learn LISP, and stumbled in SICP upon=20
>=20
> But first, let's talk about LISP, Lisp, Scheme and Common Lisp.

[...]
=20
> Finally, since you're asking on  news:comp.lang.lisp, perhaps you want
> to learn Common Lisp, which is certainly the best option if you want
> to use lisp professionaly IMO.  Check http://cliki.net/ which has all
> the pointers toward educational resources, implementations,
> libraries, etc, about Common Lisp.

Thank you for your introduction.
Well I am interested in building real programs in Lisp, not
primarily in the academic or historical aspects of it but
because of them.

My motivation stems from a finding in my basement.
I found an old Hasselblad 500 C/M photo camera from the 1970ies.
While playing, learning and photographing with it I was astonished by
the pure quality and longevity of this old design.
You can put a digital back on it in 1 minute and you have a modern
camera that still outperforms many of the current top cameras in regard
to photo quality.

That brought me to the conclusion that Victor Hasselblad made a very
good abstraction of the problem of making photos. Also he made a modular
design. The camera is in an abstract sense correct and flexible, both
preconditions for longevity.

Well, what has this to do with Lisp?

In a world of never ending programming fashions (which are beginning to
bore me after 30 years of programming in different languages), there
has to be an "essence" of programming, as there is for example an
"essence" of music.

Time has the feature to distil the essence of human made things.

=46rom my observations Lisp has survived centuries of wild development and
change. I hope that is has the "essence" of programming and therefore
maybe the eternalness of for example Mozart's music. (which I love btw.)

To find that out for myself I started the endeavour to learn Lisp.

> As this is a Common Lisp oriented forum, I will assume you've
> installed a Common Lisp implementation, and quicklisp=20
>=20
> http://www.cliki.net/Getting%20Started

Thank you for the helpful link, I was not aware of.
As on old Emacs user I used the *scratch* buffer for experimenting with
lisp. But I am going to install CL.

In regard to books SICP was already in my library (so far unread) so I
picked that up and started reading. I ordered Peter Seibels Practical
Common Lisp, but I have to wait a few weeks for arrival.
=20
> Now you see the problem I hope.  When you have a cons cell that
> contains a cons cell in its cdr slot, the lisp printer cannot fathom
> it's a cons cell, but assumes instead that it's a list.  Therefore
> instead of printing:
>=20
>    ((1 2) . (3 4))
>=20
> it prints:
>=20
>    ((1 2) 3 4)

Maybe I begin to understand...
Let's see it from another perspective:

cdr is not defined as giving the second element of a pair or list,
but to return the remainder of a sequence after the first element.
The remainder after the first element in the example is itself a
sequence, so there is no need to write it as a list.
Since car is defined of returning only the first element and not a
sequence, it has to be a list, if I want a sequence of 2 lists whose
lists are returned by car and cdr.

The remainder (cdr) of=20

((1 2) 3 4)=20

after the first element (1 2)=20

is 3 4 which is the list=20

(3 4)

Am I correct?=20

Again thank you very much for your help.

--
Greg=20
                                    =20

0
3/26/2013 8:17:00 AM
gregor writes:

> Maybe I begin to understand...
> Let's see it from another perspective:
> 
> cdr is not defined as giving the second element of a pair or list,

It does return an element of a pair, but not an element of a list.
Some pairs are lists: ((1 2) . (3 4)) is ((1 2) 3 4).

The cdr is (3 4). You can call it the second element of the pair, but
the second element of the list is 3. Different notions of element-of.

Alternative names "first" and "rest" for "car" and "cdr" make sense
for a list; "second" can then be used to pick the second element of
the list, and "third", third.

For a pair, I don't know any _better_ names for the two elements. The
important thing in a pair is not which is first but which is which.

:)
0
jpiitula2 (679)
3/26/2013 8:42:23 AM
On Tuesday, 26 March 2013 16:42:23 UTC+8, Jussi Piitulainen  wrote:

> For a pair, I don't know any _better_ names for the two elements. The
> important thing in a pair is not which is first but which is which.

Something like LEFT and RIGHT probably...
0
lokedhs (54)
3/26/2013 9:07:25 AM
In article <88882ab6-bde3-4257-a38c-af189e79d7fa@googlegroups.com>,
 Elias Mårtenson <lokedhs@gmail.com> wrote:

> On Tuesday, 26 March 2013 16:42:23 UTC+8, Jussi Piitulainen  wrote:
> 
> > For a pair, I don't know any _better_ names for the two elements. The
> > important thing in a pair is not which is first but which is which.
> 
> Something like LEFT and RIGHT probably...

I like FST and RST (first FirST and ReST) because they can be composed 
the way CAR and CDR are: FFST==CAAR, RRRST==CDDR, RFST==CDAR, etc.

rg
0
rNOSPAMon (1927)
3/26/2013 5:22:07 PM
gregor <gregor@ediwo.com> writes:

> My motivation stems from a finding in my basement.
> I found an old Hasselblad 500 C/M photo camera from the 1970ies.
> While playing, learning and photographing with it I was astonished by
> the pure quality and longevity of this old design.
> You can put a digital back on it in 1 minute and you have a modern
> camera that still outperforms many of the current top cameras in regard
> to photo quality.
>
> That brought me to the conclusion that Victor Hasselblad made a very
> good abstraction of the problem of making photos. Also he made a modular
> design. The camera is in an abstract sense correct and flexible, both
> preconditions for longevity.
>
> Well, what has this to do with Lisp?
>
> In a world of never ending programming fashions (which are beginning to
> bore me after 30 years of programming in different languages), there
> has to be an "essence" of programming, as there is for example an
> "essence" of music.
>
> Time has the feature to distil the essence of human made things.
>
> From my observations Lisp has survived centuries of wild development and
> change. I hope that is has the "essence" of programming and therefore
> maybe the eternalness of for example Mozart's music. (which I love btw.)
>
> To find that out for myself I started the endeavour to learn Lisp.

That's entirely correct.  Lisp is the Hasselblad camera of programming
languages.


>> As this is a Common Lisp oriented forum, I will assume you've
>> installed a Common Lisp implementation, and quicklisp 
>> 
>> http://www.cliki.net/Getting%20Started
>
> Thank you for the helpful link, I was not aware of.
> As on old Emacs user I used the *scratch* buffer for experimenting with
> lisp. But I am going to install CL.
>
> In regard to books SICP was already in my library (so far unread) so I
> picked that up and started reading. I ordered Peter Seibels Practical
> Common Lisp, but I have to wait a few weeks for arrival.
>  
>> Now you see the problem I hope.  When you have a cons cell that
>> contains a cons cell in its cdr slot, the lisp printer cannot fathom
>> it's a cons cell, but assumes instead that it's a list.  Therefore
>> instead of printing:
>> 
>>    ((1 2) . (3 4))
>> 
>> it prints:
>> 
>>    ((1 2) 3 4)
>
> Maybe I begin to understand...
> Let's see it from another perspective:
>
> cdr is not defined as giving the second element of a pair or list,
> but to return the remainder of a sequence after the first element.
> The remainder after the first element in the example is itself a
> sequence, so there is no need to write it as a list.
> Since car is defined of returning only the first element and not a
> sequence, it has to be a list, if I want a sequence of 2 lists whose
> lists are returned by car and cdr.
>
> The remainder (cdr) of 
>
> ((1 2) 3 4) 
>
> after the first element (1 2) 
>
> is 3 4 which is the list 
>
> (3 4)
>
> Am I correct? 

Yes. 

A cons cell can be considered the node of a binary tree, with car and
cdr being its left and right children.  Take the ascii-art diagrams of
my previous messages, and rotate them 45 degree clockwise.

    ((1 2) 3 4) 
  = ((1 2) . (3 4))
  = ((1 . (2 . nil)) . (3 . (4 . nil)))
  =
                [*|*]
                /   \
              /       \
           [*|*]     [*|*]
           /   \     /   \
          1  [*|*]  3  [*|*]
             /  \      /   \
            2   NIL   4    NIL


When working with lists, it's better to use first and rest (and second,
third, listp, endp, etc)  rather than the similar functions car and cdr
(and cadr, caddr, consp, null, etc), to indicate that you're working at
the abstraction level of a list, and not of some cons cell structure.



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.
0
pjb (7869)
3/26/2013 8:25:43 PM
Pascal J. Bourguignon wrote, On 3/26/2013 2:25 PM:
> That's entirely correct.  Lisp is the Hasselblad camera of programming
> languages.
Me thinks a better metaphor/analogue would be "Lisp is the 
technical/view camera of programming languages. I'll assume that you all 
understand this unless asked for further elaboration. I also understand 
that I'm moving even further off thread topic.
-- 
Jeff Barnett

0
jbbrus (38)
3/26/2013 10:04:13 PM
In article <88882ab6-bde3-4257-a38c-af189e79d7fa@googlegroups.com>,
 Elias M�rtenson <lokedhs@gmail.com> wrote:

> On Tuesday, 26 March 2013 16:42:23 UTC+8, Jussi Piitulainen  wrote:
> 
> > For a pair, I don't know any _better_ names for the two elements. The
> > important thing in a pair is not which is first but which is which.
> 
> Something like LEFT and RIGHT probably...

I wonder if Hebrew-speaking programmers draw cons cell diagrams with the 
CAR on the right and CDR on the left.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
barmar (6125)
3/27/2013 5:02:09 AM
Barry Margolin wrote, On 3/26/2013 11:02 PM:
> I wonder if Hebrew-speaking programmers draw cons cell diagrams with the
> CAR on the right and CDR on the left.
>
As you well know CAR and CDR were abbreviations for Contents of the 
{Address|Decrement} register - two fields in a computer instruction 
word. If the ancients had little|big Indian issues, you would have made 
a bilingual joke that would be humorous in Chinese as well as MIT English!
-- 
Jeff Barnett
0
jbbrus (38)
3/27/2013 5:27:22 AM
RG writes:

> In article <88882ab6-bde3-4257-a38c-af189e79d7fa@googlegroups.com>,
>  Elias Mårtenson wrote:
> 
> > On Tuesday, 26 March 2013 16:42:23 UTC+8, Jussi Piitulainen  wrote:
> > 
> > > For a pair, I don't know any _better_ names for the two
> > > elements. The important thing in a pair is not which is first
> > > but which is which.
> > 
> > Something like LEFT and RIGHT probably...
> 
> I like FST and RST (first FirST and ReST) because they can be
> composed the way CAR and CDR are: FFST==CAAR, RRRST==CDDR,
> RFST==CDAR, etc.

The same can be done with LT and RT, for LefT and RighT, without
suggesting that each pair is a backbone of a list.

I do believe that CAR and CDR are still here precisely because they
carry so little meaning - much less than LEFT and RIGHT. Various
alternatives are good for some purpose or other but not for all
purposes because they suggest a meaning that may be inappropriate.

For example, an item in an association list, surely as old as the pair
itself, really has a KEY and a VALUE, not LEFT and RIGHT, and not
FIRST and REST.
0
jpiitula2 (679)
3/27/2013 8:41:16 AM
On Wed, Mar 27 2013, Jussi Piitulainen wrote:

> RG writes:
>
>> In article <88882ab6-bde3-4257-a38c-af189e79d7fa@googlegroups.com>,
>>  Elias Mårtenson wrote:
>> 
>> > On Tuesday, 26 March 2013 16:42:23 UTC+8, Jussi Piitulainen  wrote:
>> > 
>> > > For a pair, I don't know any _better_ names for the two
>> > > elements. The important thing in a pair is not which is first
>> > > but which is which.
>> > 
>> > Something like LEFT and RIGHT probably...
>> 
>> I like FST and RST (first FirST and ReST) because they can be
>> composed the way CAR and CDR are: FFST==CAAR, RRRST==CDDR,
>> RFST==CDAR, etc.
>
> The same can be done with LT and RT, for LefT and RighT, without
> suggesting that each pair is a backbone of a list.
>
> I do believe that CAR and CDR are still here precisely because they
> carry so little meaning - much less than LEFT and RIGHT. Various
> alternatives are good for some purpose or other but not for all
> purposes because they suggest a meaning that may be inappropriate.

I think that CAR/CDR are still here because the names are much less
important than the underlying concept.  Those who grasp the concept care
very little about the names, which are of course arbitrary, but they
matter so little that changing them is not a priority.

One could have the exact same conversation about a lot of notation,
especially in mathematics, there is so much arbitrary/historical stuff
out there, but it does not matter much in the end.

Best,

Tamas
0
tkpapp (998)
3/27/2013 12:33:29 PM
In article <qotli99qloz.fsf@ruuvi.it.helsinki.fi>,
 Jussi Piitulainen <jpiitula@ling.helsinki.fi> wrote:

> RG writes:
> 
> > In article <88882ab6-bde3-4257-a38c-af189e79d7fa@googlegroups.com>,
> >  Elias Mårtenson wrote:
> > 
> > > On Tuesday, 26 March 2013 16:42:23 UTC+8, Jussi Piitulainen  wrote:
> > > 
> > > > For a pair, I don't know any _better_ names for the two
> > > > elements. The important thing in a pair is not which is first
> > > > but which is which.
> > > 
> > > Something like LEFT and RIGHT probably...
> > 
> > I like FST and RST (first FirST and ReST) because they can be
> > composed the way CAR and CDR are: FFST==CAAR, RRRST==CDDR,
> > RFST==CDAR, etc.
> 
> The same can be done with LT and RT, for LefT and RighT, without
> suggesting that each pair is a backbone of a list.

But the whole point of FST and RST is to suggest that the cons cell is 
being used as a list.  On those rare occasions when I'm using a cons 
cell as a cons cell I will use CAR and CDR.  But most of the time 
they're used as lists.  That is why Lisp is called Lisp and not Consp.

rg
0
rNOSPAMon (1927)
3/27/2013 5:25:55 PM
Jeff Barnett <jbbrus@comcast.net> writes:

> Barry Margolin wrote, On 3/26/2013 11:02 PM:
>> I wonder if Hebrew-speaking programmers draw cons cell diagrams with the
>> CAR on the right and CDR on the left.
>>
> As you well know CAR and CDR were abbreviations for Contents of the
> {Address|Decrement} register - two fields in a computer instruction
> word. 

Actually, it's {Address|index|Decrement|opcode}
with 3 bits for index, and 3 bits for opcode, and 15 bits for Address
and for Decrement.

http://swtch.com/~rsc/regexp/ibm7094.html

Hence the tag bits (there were instructions to fetch the index and the
opcode, as well as the address and the decrement, therefore it was very
easy to get the "tags" from the word, and there were instructions to
combine those parts into a word. 

So the cons cell comes directly from the architecture of the
704/709/7090, as well as EVAL, since this processor also had the XEC
instruction which executed a given instruction.


> If the ancients had little|big Indian issues, 

Nope, it wasn't Little Bull and Big Horn.  There's no indian in
computers, just ends of eggs.  And as everybody knows, eggs have little
ends and big ends, and there are two camps, those who eat them from the
little end, and those who eat them from the big end.

I like my eggs from the little end, but my bytes from the big end.


> you would have
> made a bilingual joke that would be humorous in Chinese as well as MIT
> English!

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.
0
pjb (7869)
3/27/2013 7:31:23 PM
Jussi Piitulainen <jpiitula@ling.helsinki.fi> writes:

> RG writes:
>
>> In article <88882ab6-bde3-4257-a38c-af189e79d7fa@googlegroups.com>,
>>  Elias M�rtenson wrote:
>> 
>> > On Tuesday, 26 March 2013 16:42:23 UTC+8, Jussi Piitulainen  wrote:
>> > 
>> > > For a pair, I don't know any _better_ names for the two
>> > > elements. The important thing in a pair is not which is first
>> > > but which is which.
>> > 
>> > Something like LEFT and RIGHT probably...
>> 
>> I like FST and RST (first FirST and ReST) because they can be
>> composed the way CAR and CDR are: FFST==CAAR, RRRST==CDDR,
>> RFST==CDAR, etc.
>
> The same can be done with LT and RT, for LefT and RighT, without
> suggesting that each pair is a backbone of a list.
>
> I do believe that CAR and CDR are still here precisely because they
> carry so little meaning - much less than LEFT and RIGHT. Various
> alternatives are good for some purpose or other but not for all
> purposes because they suggest a meaning that may be inappropriate.
>
> For example, an item in an association list, surely as old as the pair
> itself, really has a KEY and a VALUE, not LEFT and RIGHT, and not
> FIRST and REST.

(defun fetch (cons) (aref *memory* (- (car cons) (cdr cons))))
;; meaning restored :-)


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.
0
pjb (7869)
3/27/2013 7:33:01 PM
Pascal J. Bourguignon wrote:

> As this is a Common Lisp oriented forum

No, it isn't.  It's not comp.lang.cl, it's comp.lang.lisp.

And don't try to erase my hard drive.

Since CL is the antithesis of a Lispy language, it is
off-topic here.

"The good news is, it's not Lisp that sucks, but Common Lisp."
 --- Paul Graham
0
w_a_x_man (3241)
3/28/2013 12:24:34 PM
> I found an old Hasselblad 500 C/M photo camera from the 1970ies.

Nice analogy, I am myself shooting pictures with an antique. .)

> In a world of never ending programming fashions (which are beginning to
> bore me after 30 years of programming in different languages), there has
> to be an "essence" of programming, as there is for example an "essence" of
> music.

Then lisp is for you. Lisp has a somewhat steep learning curve, as
programming has in general. But once you get the core concepts (for me
that took a year or so) you will appreciate Lisp's extensible nature.

Also worth checking out in that regard: Forth.
0
max471 (38)
4/4/2013 8:20:31 PM
Reply:

Similar Artilces:

Changing (1,2,3,4,5...) to (1,1,2,2,3,3,4,4,5,5...)
Hi All, I have a column vector of numbers that I would like to extrapolate by "doubling up": e.g. turn 2 4 6 8 into: 2 2 4 4 6 6 8 8 any ideas on an easy vectorised way to do this? TIA, Rob v=repmat([2; 4; 6; 8].',2,1); v=v(:) "Robert Barrie" <askme@ifuwant.com> wrote in message <hlt7kp$rut$1@fred.mathworks.com>... > Hi All, > > I have a column vector of numbers that I would like to extrapolate by "doubling up": > > e.g. turn > 2 > 4 > 6 > 8 > > into: > 2 > 2 > 4 > 4 > 6 > 6 > 8 >...

how can i write this statement labels=[1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;]; in compress fo
How to write it in compact form to avoid repetition "shah " <shahkhn3@gmail.com> wrote in message <lodugh$8hr$1@newscl01ah.mathworks.com>... > How to write it in compact form to avoid repetition You'll find in this thread different solutions for similar question http://www.mathworks.fr/matlabcentral/newsreader/view_thread/335814 Bruno ...

[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 3;....;n n n n n]
Hi, Anybody knows how to create this matrix but without using any loops? a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ] Thank you. Hana. Hana wrote: > Hi, > Anybody knows how to create this matrix but without using any loops? > a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ] HELP REPMAT - Randy Hana wrote: > > > Hi, > Anybody knows how to create this matrix but without using any > loops? > a=[1 1 1 1 1 ;2 2 2 2 2 ;3 3 3 3 3 ;.......;n n n n n ] > > Thank you. > Hana. Hope this isn't homework. >> repmat([1:n]'...

Upgrade from VO 1 - 2 - 2..1 -2.2 - 2.3 -2.4 - 2.5 - 2.6 - 2.7
About upgrade 2.5 - 2.7 at $ 384.00 For most products I'm using - the updates (2.0 - 2.1 - 2.7) are free... 2.0 to 3.0 might be worth + 10-30% of the original price? VO is + full price again & again - Full program price for every minor upgrade/bug-fix? I dropped out of the money/bugs [VO] at 2.5 after starting at 1.0 more than 10 years ago. Certainly whoever is making VO have to make a living; earning moneys: - that is OK! A 10 years old VO site; - 10 years later, how much have changed? http://www.yi.com/prany/cavo/cavofront.htm Even MS is not ...

[0 0 1 1 2 2 3 3 4 4 ... n n]
Is there a way to achieve a vector like the one below without using loops? [0 0 1 1 2 2 3 3 4 4 ... n n] "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <kp999d$a8e$1@newscl01ah.mathworks.com>... > Is there a way to achieve a vector like the one below without using loops? > > [0 0 1 1 2 2 3 3 4 4 ... n n] You could try this: floor(0:1/rep:n+1-1/rep) where rep is the number of repetitions (2 in your case) Hi, a cool way to do that is using the kronecker product kron(0:n,[1 1]); "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <...

{{1,2,3},{4,5,6},...} --> {1,2,3,4,5,6,...} ?
What's a simple way to turn an "array of arrays" into one big array? Essentially I want to concatenate every member of a cell array. I was thinking something like this: feval(horzcat,deal(array)) But that doesn't seem to work. Is there a similar form that does? thanks, Tobin http://web.pas.rochester.edu/~tobin/ In article <Pine.GSO.4.64.0604051040090.34@apocalypse.OCF.Berkeley.EDU>, Tobin Fricke <fricke@ocf.berkeley.edu> wrote: > What's a simple way to turn an "array of arrays" into one big array? > > Essentially I want to conc...

convert String "1;2;3;4;5;" to Array [1, 2, 3, 4, 5]
I'm trying to convert a String of numbers that are separated by semicolons to an Array---totally for fun, to stretch my ruby understanding, fyi. I use the Array in a while loop which does work when the Array looks like = [1,2,3,4,5,...]---so that part is working. But I want to use ruby to convert a String = "1;2;3;4;5;6;7;8;9;10" into an Array [1,2,3,4,5,...] so that I can use these values. I've tried many a method, but can't seem to get the desired result; I've tried gsub(/\;/, ","), eval (), and others. ########## raw_data = "1;2;3...

Load average differences between Apache 1.3.37/PHP 4.4.6 and Apache 2.2.4/PHP 5.2.1
Hi folks, I've encountered something rather strange. This morning, I upgraded our production server, providing web services for our library website, from Apache 1.3.37/PHP 4.4.6 to Apache 2.2.4/PHP 5.2.1. The server, which normally exhibits a load average below 1 most of the time, spiked to loads that approached 100 if left alone. The interesting part of this is that this load average seems to be almost artificial - it appears to be caused by httpd processes stuck in a "closing connection" state (TIME_WAIT, in netstat). These processes are still running according t...

Possible to block mail from SMTPs whose IPs are in 12345678 form? (not 1.2.3.4 or host [1.2.3.4] )
Hello. I started getting some spam on my network (its basically always the same crap - some "doctor" soliciting some drugs...) and I've been adding entries to my /etc/mail/access file (and re hashing it of course)... But recently, in the mail source, the "received from" lines have been showing a number, like 123456789, instead of a traditional ip (1.2.3.4), for the SMTP that relayed the email to me, and I'm wondering if it's possible, and a good idea (or RFC legal) to block IP's that aren't either in a.b.c.d or "hostname [a.b.c.d]" form...

do matlab has combination fuction? for example, I want to selcet 2 numbers from 1,2,3,4,5,then I want to get following array:[1,2],[1,3],.....
undefined In article <ef33da0.-1@webx.raydaftYaTP>, dincent <accessdxt123@163.com> wrote: > undefined I might have responded to this with a reasonable answer, had you NOT posted your entire question as the subject title and left the body of the post as "undefined". Too bad. John -- The best material model of a cat is another, or preferably the same, cat. A. Rosenblueth, Philosophy of Science, 1945 Those who can't laugh at themselves leave the job to others. Anonymous ...

Does 4/2/2= (4/2)/2 =1 OR = 4/(2/2)=4
I don't have matlab and I am trying to translate some simple matlab code. Does 4/2/2 = (4/2)/2 = 1 or 4/2/2 = 4/(2/2) = 4 On 9/11/2012 9:43 AM, sarah.englander@gmail.com wrote: > I don't have matlab and I am trying to translate some simple matlab code. > > Does 4/2/2 = (4/2)/2 = 1 yes. At a given precedence level (and obviously two of the same operators are the same level) evaluation proceeds from LtoR. ....snip... <http://www.mathworks.com/help/techdoc/matlab_prog/f0-40063.html#f0-38155> -- dpb <none@non.net> wrote in message <...

compiling gcc 3.2.3 on aix 4.3.2 using gcc 3.2.1
All, I am trying to compile gcc-3.2.3 on aix-4.3.2 using a prebuilt gcc-3.2.1. I am using GNU make, native as,ar,ld. There are the errors I get. Can anyone help? thx balaji $ gmake bootstrap gmake[1]: Entering directory `/mnt/gcc-3.2.3/aix/libiberty' gmake[2]: Entering directory `/mnt/gcc-3.2.3/aix/libiberty/testsuite' gmake[2]: Nothing to be done for `all'. gmake[2]: Leaving directory `/mnt/gcc-3.2.3/aix/libiberty/testsuite' gmake[1]: Leaving directory `/mnt/gcc-3.2.3/aix/libiberty' gmake[1]: Entering directory `/mnt/gcc-3.2.3/aix/zlib' : gmake ; exec true "AR_...

how to "(1-3*x^2)/(1-3*x+x^2+2*x^3) => 1/(1-2*x) + x/(1-x-x^2)"?
hi normal(1/(1-2*x) + x/ (1-x-x^2),expanded); 1/(1-2*x) + x/(1-x-x^2) => (1-3*x^2)/(1-3*x+x^2+2*x^3) how to do the reverse? dillogimp@gmail.com writes: > normal(1/(1-2*x) + x/ (1-x-x^2),expanded); > 1/(1-2*x) + x/(1-x-x^2) => (1-3*x^2)/(1-3*x+x^2+2*x^3) > how to do the reverse? convert(%,parfrac,x); -- Joe Riel ...

Notation: R(a,k) denotes the rising factorial a(a+1)...(a+k-1 ...the certificate being 2 2 2 (5 m - 12 m p - 2 m + 8 p + 3 n m - n
Notation: R(a,k) denotes the rising factorial a(a+1)...(a+k-1 ...the certificate being 2 2 2 (5 m - 12 m p - 2 m + 8 p + 3 n m - n - 4 n p + 1 + 4 p) n -------------------------------------------------------------, QED . ... Musatov ...

Web resources about - Newbie question; why (cons (list 1 2) (list 3 4)) is ((1 2) 3 4) and not ((1 2) (3 4)) - comp.lang.lisp

Resources last updated: 2/4/2016 8:55:26 AM