Scheme pass-by-reference

前端 未结 7 1450
忘了有多久
忘了有多久 2021-02-08 11:09

How can I pass a variable by reference in scheme?

An example of the functionality I want:

(define foo
  (lambda (&x)
    (set! x 5)))

(define y 2)

         


        
相关标签:
7条回答
  • 2021-02-08 12:10

    lambda!

    (define (foo getx setx)
      (setx (+ (getx) 5)))
    
    (define y 2)
    (display y)(newline)
    
    (foo
     (lambda () y)
     (lambda (val) (set! y val)))
    
    (display y)(newline)
    
    0 讨论(0)
提交回复
热议问题