Schematic: Lists of three dashed elements returning strangely (for example, an infix operator?)

I am a new student of Scheme / Racket, so please excuse any gross syntax errors.

Today in the class it appeared that the list of schemes '(a, b, c) must be invalid, but when we started it, it returned:

 >'(a . b . c) (bac) 

It makes no sense. Afaik, the translator must create a cons cell with the car 'a and cdr' b, and c must be invalid. However, the translator is doing something really strange here. This works with C # lang schema, #lang racket and others. We use DrRacket as an interpreter.

Interesting that

 >'(a . b . c . d) 

throws an exception and dies.

I am very curious and would like to understand this, since I am new to the language. Google was very useless (perhaps because the search terms are ambiguous) Thank you!

EDIT: This may be because '(a . b . c) interpreted using b as an infix operator. For example: >(4 . + . 6) returns 10. Maybe the interpreter uses b as an operator? those. (bac) , like (+ 4 6) , infix-wise.

The experience says:

 >(define b +) >(define a 4) >(define c 6) >(a . b . c) 10 

So, I think this solves the problem, but I still do not fully understand the use of ".". operator in this case. I think we have solved this, but a deeper understanding will be appreciated!

+6
source share
2 answers

Short answer: you understand. For more information about this particular point usage in terms of rocket usage, see the infix documentation in the Racket docs.

+8
source

This is a feature of the Racket reader. (See John's answer.)

For other implementations, you can use readable S-expressions to read infix expressions instead. It uses curly braces. for example, {3 + 4} reads as (+ 3 4) . Even more special (than the Racket infix reader), you can use {3 + 4 + 5} or {3 + 4 + 5 + 6} ; they will be considered as (+ 3 4 5) and (+ 3 4 5 6) respectively.

+4
source

Source: https://habr.com/ru/post/897495/


All Articles