Scheme pass-by-reference

前端 未结 7 1479
忘了有多久
忘了有多久 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:00

    You can use a macro:

    scheme@(guile-user)> (define-macro (foo var)`(set! ,var 5))
    scheme@(guile-user)> (define y 2)
    scheme@(guile-user)> (foo y)
    scheme@(guile-user)> (display y)(newline)
    5
    

提交回复
热议问题