Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are pair and list different in Scheme?

Tags:

I wonder whether '(1 . 2) and '(1 2) mean the same data (equal to each other) in Scheme or not? I think they are the same thing, is this correct?

like image 336
Thomson Avatar asked May 15 '11 05:05

Thomson


People also ask

What is a pair in Scheme?

Pairs are used to combine two Scheme objects into one compound object. Hence the name: A pair stores a pair of objects. The data type pair is extremely important in Scheme, just like in any other Lisp dialect.

What is a list in Scheme?

In contrast to Scheme's unstructured data types, such as symbols and numbers, lists are structures that contain other values as elements. A list is an ordered collection of values. In Scheme, lists can be heterogeneous, in that they may contain different kinds of values.

How does list work in Scheme?

Scheme Lists. The first argument of cons may be any Scheme object, and the second is a list; the value of (cons x xs) is a new list which contains x followed by the elements of xs . (Scheme's way of printing lists uses a shorthand which hides the final () .


1 Answers

No, they are not the same.

'(1 . 2) means (cons 1 2)

whereas

'(1 2) means (cons 1 (cons 2 nil))

like image 134
hammar Avatar answered Nov 13 '22 09:11

hammar