Scheme pass-by-reference

前端 未结 7 1456
忘了有多久
忘了有多久 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)
    

提交回复
热议问题