[racket] Modifying bindings in parent environment

From: Jakub Piotr Cłapa (jpc-ml at zenburn.net)
Date: Sun Aug 8 22:27:11 EDT 2010

On 09.08.10 03:59, Joe Snikeris wrote:
> Hi all,
> Is there a way for a procedure to modify bindings in it's parent
> environment?  I suppose the technique would be similar to passing a
> C-style pointer to the procedure.
> For example:
> (define p 1)
> (f p 3)
> p
>> 3

Something like this?

#lang racket
(define-syntax-rule (make-accessor b)
     [() b]
     [(v) (set! b v)]))

(define (f x y)
   (let ([old-x (x)])
     (x y)
     (list old-x (x))))

(let ([b 15])
   (list b
         (f (make-accessor b) 3)

Jakub Piotr Cłapa

Posted on the users mailing list.