Aslan986
Aslan986

Reputation: 10314

How does this define work?

I have this piece of scheme code:

(define (x . y) y)
(x 1 2 3)

and I know it equivalent to:

'(1 2 3)

But i can't understand why.

What does the first line of code do?

Thank you.

Upvotes: 2

Views: 125

Answers (1)

OwnWaterloo
OwnWaterloo

Reputation: 1983

The first line (define (x . y) y) is equivalent to (define x (lambda y y)), according to 5.2 Definitions(the last clause).

And (lambda y y) is a procedure; when called all the arguments will stored in a newly allocated list. e.g. list could be defined as (define list (lambda xs xs)). (See 4.1.4 Procedures the second form of formal parameters.)

So (x 1 2 3) is equivalent to (list 1 2 3).

Upvotes: 3

Related Questions