Why does '(a . b . c) evaluate to (b a c) in PLT-Scheme 372?

拥有回忆 提交于 2020-01-03 03:10:54

问题


I'm trying to understand the relations between pair, cons, dotted tuples and proper list in PLT-Scheme 372. The detailed context of my question is as follows:

After reading some textbook and doing trial-and-error, I have got the following understanding and intuitive ideas (I may be wrong...):

  1. all lists are pairs, e.g.:

    (pair? (list 'a 'b 'c)) => #t

  2. all conses are pairs, e.g.:

    (pair? (cons 'a (cons 'b 'c))) => #t

  3. some dot-separated tuples are pairs, e.g.:

    (pair? '(a . b)) => #t
    (pair? '(a . b . c)) => #t in Standard R5RS it's not legal syntax.

Then I bumped into this problem: Why does '(a . b . c) evaluate to (b a c)? Where can I find a complete usage manual of dot?

'(a . b)                => (a . b)   
'(a . b . c)            => (b a c)
'(a . b . c . d)        => illegal use of `.'
'(cons 'a (cons 'b 'c)) => (a b . c)

回答1:


For Racket (PLT), there is a good description here.

Regarding the syntax (a . b . c) look at the bottom of the page, it's a Racket-specific reader extension designed to express typical tests like (< 1 2) as (1 . < . 2).



来源:https://stackoverflow.com/questions/20816353/why-does-a-b-c-evaluate-to-b-a-c-in-plt-scheme-372

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!