1

I'm recently implementing a scheme interpreter using scheme itself. I know that single dot notation means constructing a pair or defining a lambda with multiple parameters. But then I discover that

'(3 . 4 . 5)

evaluates to

'(4 3 5)

and

(define (a . b . c) (displayln b) (displayln c))
(a 4 3)

it will print (weird that #\newline is not printed)

(4 3)>

Can somebody explain the meaning of double dot notation?

5
  • according to docs.racket-lang.org/guide/Pairs__Lists__and_Racket_Syntax.html , (define (a . b . c) ... ) should be evaluated as (define (b a c) ...). so (a 1 2) should raise error "a: undefined". Are there any function which named a in your source code ?
    – ymonad
    Oct 25, 2014 at 6:44
  • Also note that the double dot notation is a Racket extension not used in standard Scheme.
    – soegaard
    Oct 25, 2014 at 6:46
  • 1
    possible duplicate of Why does '(a . b . c) evaluate to (b a c) in PLT-Scheme 372?
    – uselpa
    Oct 25, 2014 at 7:30
  • @ymonad yeah that 'define' was my typo. Thanks so much for these comments.
    – Poligun
    Oct 25, 2014 at 8:17
  • In scheme (a language conforming to one of the standard reports) this is invalid syntax and won't work. PLT Scheme is not a Scheme language but an application suit. The new name is racket. Amongst the languages you can choose scheme which is the old name of racket which isn't a language following a standard report. Since this is #!racket specific it has nothing to do with scheme
    – Sylwester
    Oct 25, 2014 at 9:46

1 Answer 1

1

From http://docs.racket-lang.org/reference/reader.html

If the reader finds three or more data between the matching parentheses, and if a pair of delimited .s surrounds any other than the first and last elements, the result is a list containing the element surrounded by .s as the first element, followed by the others in the read order. This convention supports a kind of infix notation at the reader level.

Racket provides the double dot syntax for the purpose of infix function calls:

(2 . + . 3) => 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.