How does Racket handle (detect (f (xy)) the body)?

I study Racket and wrote this definition:

(define y 2)
(define (f (x y))
  (print x)
  (print y))

When I value (f 1), I am xattached to 1, and yattached to 2. This is very strange to me. How does this expression expand? What does the interpreter do with this?

+4
source share
2 answers

This is an optional argument.

The grammar for definitions in Racket is contained in the documentation.

3.14 Definitions: define, define-syntax, ...

(define id expr)
(define (head args) body ...+)

head  =       id
      |       (head args)

args  =       arg ...
      |       arg ... . rest-id

arg   =       arg-id
      |       [arg-id default-expr]
      |       keyword arg-id
      |       keyword [arg-id default-expr]

Lisping Common Lisp, , . [arg-id default-expr] , . ,

(define (f (x y)) …)

f , 0 1 . , y. , y. , (f), y:

enter image description here

Racket Robby Findler Tony Garnock-Jones [racket] (define (f ( xy))), y .

R5RS

RS 5 RS. :

5.2

, , . a .

:

(define <variable> <expression>)
(define (<variable> <formals>) <body>)

, , , ( ).

(define <variable>
  (lambda (<formals>) <body>)).

(define (<variable> . <formal>) <body>)

.

(define <variable>
  (lambda <formal> <body>)).

Dr.Racket R5RS:

Dr. Racket Screenshot

+6

Racket (argument-name default-value) ( , - ).

, (define (f (x y)) ...) f, x, y.

+3

Source: https://habr.com/ru/post/1545671/


All Articles