How allowed * Defined by Chez Scheme / Racket?

How is let*defined in Chez Scheme / Racket? In particular, why is this first example rated at 6 ...

(let* ((let +) (a (let 2 4)))
    a)

... when my understanding from Exercise 3.1.3 is that it let*can be expanded to nested let(or even nested let*), but an extension of the above example, how would one expect the interpreter to do wrong results?

(let ((let +))
    (let (a (let 2 4))
        a))

Is the implementation different from the exercise? I would expect the first example to also result in an error due to the new definition let.

+4
source share
3 answers

, let* ( , , " ", Racket, Asumu Takikawa):

(define-syntax let*
  (syntax-rules ()
    ;; base case
    ((_ () body ...)
     (let ()
       body ...))

    ;; recursive case
    ((_ (binding next ...) body ...)
     (let (binding)
       (let* (next ...)
         body ...)))))

, , ( , ) . let* let let*, ( binding, next body) .

, let let* , , ( ) let let*.

- . , :

(define-syntax let*
  ;; bind g1 to current let, g2 to current let*
  (syntax-rules ()
    ((_ () g3 ...)
     (g1 ()
       g3 ...))
    ((_ (g4 g5 ...) g6 ...)
     (g1 (g4)
       (g2 (g5 ...)
         g6 ...)))))

g1 g6 , "gensyms" ( Lisp gensym, ). , - let let* , binding, next body - let*.

( , ): , gensyms ( , , ). , "" , (, g1, g2 .. ), , .

, , , , gensyms. , .

+2

( * ([ +] [a (let 2 4)]) a)

(LET ([let +]) (LET ([a (let 2 4)])   ))

LET let , let * ( : "" ).

, LET +, . ( 2 4), 6 (- let). 6 . , , a 6, 6.

+5

let* R7RS:

(define-syntax let*
  (syntax-rules ()
    ((let* () body1 body2 ...)
     (begin body1 body2 ...))

    ((let* ((name1 val1) (name2 val2) ...)  body1 body2 ...)
     (let ((name1 val1))
       (let* ((name2 val2) ...)
         body1 body2 ...)))))

This shows that it let*expands into nested expressions let. Your mistake arises from the fact that the hygiene macros of the circuit do not confuse the binding letwhen it let*is determined using letwhenlet* .

0
source

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


All Articles