[plt-scheme] Beginner Question
And if what you really do want is a list of two elements, where each
of those elements is a list of two numbers, do:
(list (list 1 2) (list 5 3))
or, alternatively if you want to use cons:
(cons (list 1 2) (cons (list 5 3) empty))
On Oct 4, 2009, at 4:26 PM, Carl Eastlund wrote:
> On Sun, Oct 4, 2009 at 1:34 AM, vishy <vishalsodani at gmail.com> wrote:
>> Why (cons (list 1 2) (list 5 3)), produces
>> ((1,2) 5 3) and not ((1,2),(5, 3)) thats is a list of 2 elements .
>>
>> thanks
>
> Vishy,
>
> The cons procedure adds an element to a list. If you run (cons 1
> (list 2 3)), you add the element 1 to (list 2 3) and get (list 1 2 3).
> If you run (cons (list 1 2) (list 5 3)), you add (list 1 2) as an
> element, and get (list (list 1 2) 5 3)). If your intent is to join
> the elements of two lists, the appropriate function is append.
> Running (append (list 1 2) (list 5 3)) will give you (list 1 2 5 3).
> Both methods of combination, cons and append, have their uses, so be
> careful to always choose the one you mean.
>
> --Carl
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme