Scheme pass-by-reference

前端 未结 7 1447
忘了有多久
忘了有多久 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 11:52

    Jari is right it is somewhat unscheme-like to pass by reference, at least with variables. However the behavior you want is used, and often encouraged, all the time in a more scheme like way by using closures. Pages 181 and 182(google books) in the seasoned scheme do a better job then I can of explaining it.

    Here is a reference that gives a macro that allows you to use a c like syntax to 'pass by reference.' Olegs site is a gold mine for interesting reads so make sure to book mark it if you have not already.

    http://okmij.org/ftp/Scheme/pointer-as-closure.txt

提交回复
热议问题