Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[NEWBIE]CONS,APPEND AND LIST

3,887 views
Skip to first unread message

Roberto

unread,
Dec 6, 2003, 9:57:04 AM12/6/03
to
Hi all.
Can anybody explain me the difference(s) between
CONS
APPEND
LIST
please?
Thanks a lot!
Roberto


mikel

unread,
Dec 6, 2003, 3:20:04 PM12/6/03
to
Roberto wrote:
> Hi all.
> Can anybody explain me the difference(s) between
> CONS

(CONS X Y)

makes a pair like this:

(X . Y)

In other words, X is the CAR of the pair; Y is the CDR of the pair. For
example:

(CONS 1 2) ==> (1 . 2)
(CONS 1 '(2 3)) ==> (1 2 3)

[The pair (1 . (2 3)) is the same thing as (1 2 3)].

> APPEND

(APPEND X Y)

makes a new list by replacing the final nil in X with the list Y. X and
Y must be proper lists. For example:

(APPEND '(1) '(2 3)) ==> (1 2 3)

(In fact, append takes any number of arguments and appends them in this
fashion).

(APPEND '(1 . 2) '(3 . 4))

doesn't work because the arguments are not proper lists (that is, they
are pairs, but their CDRs are not lists). APPEND only works on proper
lists (pairs whose CDRs are lists or NIL).

> LIST

Takes any number of arguments. Returns a list whose elements are the
values of those arguments in the same order they appear in the LIST
form. For example,

(LIST 1) ==> (1)
(LIST 1 2) ==> (1 2)
(LIST 1 2 '(3 4)) ==> (1 2 (3 4))
(LIST (+ 2 3)(* 2 3)) ==> (5 6)

mikel

unread,
Dec 6, 2003, 3:34:39 PM12/6/03
to
mikel wrote:

>> APPEND
>
>
> (APPEND X Y)
>
> makes a new list by replacing the final nil in X with the list Y. X and
> Y must be proper lists. For example:
>
> (APPEND '(1) '(2 3)) ==> (1 2 3)
>
> (In fact, append takes any number of arguments and appends them in this
> fashion).
>
> (APPEND '(1 . 2) '(3 . 4))
>
> doesn't work because the arguments are not proper lists (that is, they
> are pairs, but their CDRs are not lists). APPEND only works on proper
> lists (pairs whose CDRs are lists or NIL).

Oops; the last argument is allowed to be something other than a proper list.

Roberto

unread,
Dec 7, 2003, 3:55:47 AM12/7/03
to
.

"mikel" <mi...@evins.net> wrote:

[CUT]

thanks thanks thanks!!


0 new messages