-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey Sam,
On 09/28/11 16:42, Sam Tobin-Hochstadt wrote: > On Wed, Sep 28, 2011 at 10:36 AM, Marijn <[email protected]> wrote: >> >> recent talk about internal define being considered the preferred >> style made me focus on trying to use it more in my own code and >> resulted in some thoughts which I'd like to throw out there >> without much sanity checking on my part. >> >> Consider: >> >> #lang racket >> >> (require racket/mpair) >> >> (let ((value-store (mlist (mcons 'variable #f)))) (define >> (variable-ref variable) (massoc variable value-store)) (define >> (variable-set! variable value) (set-mcdr! (variable-ref variable) >> value))) >> >> (variable-ref 'variable) > > Try this: > > #lang racket > > (require racket/mpair racket/splicing) > > (splicing-let ((value-store (mlist (mcons 'variable #f)))) (define > (variable-ref variable) (massoc variable value-store)) (define > (variable-set! variable value) (set-mcdr! (variable-ref variable) > value))) > > (variable-ref 'variable) Thanks , that sure is nice! One nitpick: DrRacket (yesterday's git) wants to indent it like so: (splicing-let ((value-store (mlist (mcons 'variable #f)))) (define (variable-ref variable) (massoc variable value-store)) (define (variable-set! variable value) (set-mcdr! (variable-ref variable) value))) Marijn -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk6EIAYACgkQp/VmCx0OL2w+kACfc9wKWZ/qdB+EojzlJUwLVsG0 gCMAoJZD/xo8Uhw22l0IugOHjZ21wP/q =jfS4 -----END PGP SIGNATURE----- _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users

