[racket] splicing internal define?

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Wed Sep 28 10:42:00 EDT 2011

On Wed, Sep 28, 2011 at 10:36 AM, Marijn <hkBst at gentoo.org> 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)
-- 
sam th
samth at ccs.neu.edu



Posted on the users mailing list.