I am a new Scheme/Racket student, so please excuse any blatant syntax errors.
It came up in class today that the scheme list '(a, b, c)
should be invalid, but when we ran it, it returned:
>'(a . b . c)
(b a c)
Which makes no sense. Afaik, the interpreter should create a cons cell with car 'a and cdr 'b, and the 'c should be invalid. That said, the interpreter is doing something really strange here. This works with #lang scheme, #lang racket, and others. We are using DrRacket as the interpreter.
Interestingly,
>'(a . b . c . d)
throws an exception and dies.
I am very curious and would love to be able to understand this since I am new to the language. Google was very unhelpful (probably since the search terms are kind of ambiguous) Thank you!
EDIT:
It might be because '(a . b . c)
is interpreted with b as an infix operator. For example: >(4 . + . 6)
returns 10. Perhaps the interpreter is using b like an operator? i.e. (b a c)
like (+ 4 6)
, infix-wise.
Expermentation says:
>(define b +)
>(define a 4)
>(define c 6)
>(a . b . c)
10
So I think this solves the problem, but I still don't fully understand the use of the "." operator in this case. I think we've solved this, but any more insight would be greatly appreciated!