Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is everything a list in scheme?

Along with the book "Simply Scheme" (Second Edition) i'm watching the "Computer Science 61A - Lectures" on youtube. On the lectures , the tutor uses Stk interpreter, but i'm using chicken scheme interpreter.

In the first lecture he uses the "first" procedure which if it's called like :

(first 'hello) 

it returns "h".

On the book of "Simply Scheme" it has an example of how first can be implemented:

(define (first sent)
  (car sent))

Which to my testing and understanding works if sent is a list . I'm trying to understand if it's proper to say that "everything is a list" in scheme. To be more specific where's the list in 'hello and if there is one, why it doesn't work in first procedure as it's written in the book?

Also if every implementation is written with "everything is a list" in mind why the same code does not work in all scheme implementations?

like image 318
spk Avatar asked Jan 16 '23 01:01

spk


1 Answers

No, this is a common misconception because lists are so pervasive in Scheme programming (and often functional programming in general). Most Scheme implementations come with many data types like strings, symbols, vectors, maps/tables, records, sets, bytevectors, and so on.

This code snippet (first 'hello) is unlikely to work in most Schemes because it is not valid according to the standard. The expression 'hello denotes a symbol, which is an opaque value that can't be deconstructed as a list (the main thing you do with symbols is compare them with eq?). This is probably a quirk of Stk that is unfortunately taught by your book.

See The Scheme Programming Language for a more canonical description of the language. If you just want to learn programming, I recommend HtDP.

like image 161
Asumu Takikawa Avatar answered Jan 24 '23 05:01

Asumu Takikawa