Is everything a list in scheme?-Collection of common programming errors
Not everything is a list in Scheme. I’m a bit surprised that the example you’re showing actually works, in other Scheme interpreters it will fail, as first
is usually an alias for car
, and car
is defined only for cons
pairs. For example, in Racket:
(first 'hello)
> first: expected argument of type ; given 'hello
(car 'hello)
> car: expects argument of type ; given 'hello
Scheme’s basic data structure is the cons pair, with it it’s possible to build arbitrarily linked data structures – in particular, singly-linked lists. There are other data structures supported, like vectors and hash tables. And of course there are primitive types – booleans, symbols, numbers, strings, chars, etc. So it’s erroneous to state that “everything is a list” in Scheme.