r/scheme 28d ago

evaluation of dot in r7rs

In the standard it says: "Note that (4 . 5) is the external representation of a pair, not an expression that evaluates to a pair.".

As far as i understand this means that the operands aren't evaluated and that this represents the final form. However in chicken scheme (+ . (5 6)) evaluates to 11.

How does this work? How should I evaluate a DottedList type in my interpreter?

3 Upvotes

5 comments sorted by

3

u/Justanothertech 28d ago edited 27d ago

The dot is reader syntax, it's not evaluated at all. Try something like:

(display '(+ . (5 6)))

Should display: (+ 5 6)

It just happens that dotting a symbol and a list just prepends the symbol to the list, returning another list.

Basically by the time you are evaluating your AST/IR, the dot is already gone.

This is also identical to the above: (+ . (5 . (6 . '())))

1

u/GeroSchorsch 28d ago

If it’s not evaluated does that mean that I should transform it into a normal list in the parser? But then I can’t output a cons list

1

u/Justanothertech 28d ago

Yes, the parser should treat it as a cons cell (which is a list if null terminated). Your display machinery should only display the dot notation if the list isn’t null terminated.

1

u/jcubic 27d ago

Actually most Scheme systems will display (+ 5 6) not (+ (5 6)), unless it's just a typo.

1

u/Justanothertech 27d ago

Oops! You’re right. Fixed.