Is the list all in the scheme?

Along with the book Just a Scheme (second edition), I watch Computer Science 61A - Lectures on youtube. In lectures, the teacher uses the Stk interpreter, but I use the chicken circuit interpreter.

In the first lecture, he uses the "first" procedure, which, if called:

(first 'hello) 

it returns "h".

The book “Just a circuit” has an example of how to implement the first:

 (define (first sent) (car sent)) 

Which for my testing and understanding works if a list is sent. I'm trying to figure out if it’s right to say that “everything is a list” in the diagram. To be more specific, where is the "hello" list, and if so, why doesn't it work in the first procedure, as it is written in the book?

Also, if each implementation is written with "everything is a list" in mind, why does the same code not work in all implementations of the circuit?

+4
source share
3 answers

No, this is a common misconception because lists are so common in Schema programming (and often in functional programming in general). Most schema implementations have many types of data, such as strings, characters, vectors, maps / tables, records, sets, bytes, etc.

This piece of code (first 'hello) unlikely to work on most circuits because it is not valid according to the standard. The expression 'hello means a character that is an opaque value that cannot be decomposed into a list (most importantly, what do you do with the characters, compare them to eq? ). This is probably the Stk quirk that your book teaches unfortunately.

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

+4
source

Not everything is a list in the Scheme. I am a little surprised that the example you are showing really works, in other Scheme interpreters it will fail, because first usually an alias for car , and car is defined only for cons pair . For example, in Racket:

 (first 'hello) > first: expected argument of type <non-empty list>; given 'hello (car 'hello) > car: expects argument of type <pair>; given 'hello 

The basic data structure of a schema is a couple of minus points with which it is possible to construct arbitrarily connected data structures - in particular, simply connected lists. Other data structures such as vectors and hash tables are supported. And, of course, there are primitive types: Boolean, characters, numbers, strings, characters, etc. Therefore, it is a mistake to assert that "everything is a list" in the Scheme.

+3
source

As for the simple scheme: the functions at first and the rest are not standard from the Scheme standard, nor those that are built into DrRacket. The Simple Scheme API is designed as part of the Simply Scheme curriculum, making it easy to work with a variety of data. We cannot make too many assumptions about how a basic, low-level implementation works only from the experience of using the Simply Scheme learning language! There, the execution time costs are associated with the creation of simple things: it does not come for free.

+2
source

All Articles