File tree Expand file tree Collapse file tree 2 files changed +23
-21
lines changed Expand file tree Collapse file tree 2 files changed +23
-21
lines changed Original file line number Diff line number Diff line change 1
1
; in eval.scm
2
+ ;
3
+ ; not need to expand let* in terms of non-derived expressions
Original file line number Diff line number Diff line change 183
183
(list '> >)
184
184
(list '< <)
185
185
(list '= =)
186
+ (list 'print print)
186
187
))
187
188
188
189
(define (primitive-procedure-names )
394
395
(define (let-vals exp ) (map cadr (let-bindings exp)))
395
396
396
397
(define (let->combination exp )
397
- (make- let (let-vars exp)
398
- (let-vals exp) ; todo
399
- (let-body exp)))
398
+ (let->lambda (let-vars exp)
399
+ (let-vals exp) ; todo
400
+ (let-body exp)))
400
401
401
- (define (make- let vars values body )
402
+ (define (let->lambda vars values body )
402
403
(cons (cons 'lambda
403
404
(cons vars body))
404
405
values))
405
406
407
+ (define (make-let var-bindings body )
408
+ (cons 'let
409
+ (cons var-bindings
410
+ body)))
411
+
406
412
(define (letstar? exp )
407
413
(tagged-list? exp 'let* ))
408
414
409
415
(define (let*->nested-let exp )
410
416
(define (wrap-let-body vars values )
411
417
(cond ((and (null? vars)
412
418
(null? values))
413
- (make-let vars values (let-body exp)))
419
+ (make-let '() (let-body exp)))
414
420
((or (null? vars)
415
421
(null? values))
416
422
(error 'wrap-let-body " let vars-values length not match" ))
417
423
(else
418
- (make-let (list (car vars) )
419
- ( list (car values))
420
- (wrap-let-body (cdr vars)
421
- (cdr values))))
424
+ (make-let (list (list ( car vars)
425
+ (car values) ))
426
+ (list ( wrap-let-body (cdr vars)
427
+ (cdr values) ))))
422
428
))
423
429
(wrap-let-body (let-vars exp)
424
430
(let-vals exp) ; todo
494
500
(cons a b))
495
501
new-env)
496
502
(cons 3 4 )))
497
- (display (let*->nested-let ' (let* ((x 1 )
498
- (y (+ x 1 ))
499
- (z (+ x a ))
503
+ (assert ( equal? (seck-eval ' (let* ((x 1 )
504
+ (y (+ x a ))
505
+ (z (+ x y ))
500
506
)
501
- (+ x y z))))(newline)
502
- (assert-eq (seck-eval ' (let* ((x 1 )
503
- (y (+ x 1 ))
504
- (z (+ x a))
505
- )
506
- (+ x y z))
507
- new-env)
508
- 8
509
- =)
507
+ (+ x y z))
508
+ new-env)
509
+ 12 ))
510
510
))
You can’t perform that action at this time.
0 commit comments