It is fairly easy to create a let-immutable form yourself

(define-for-syntax (immutable-variable-transformer new-id)
   (λ (stx)
     (syntax-case stx (set!)
       [(set! x rhs)
        (raise-syntax-error #f "cannot mutate immutable variable" stx)]
       [(e ...)
        (with-syntax ([ap (datum->syntax stx '#%app)])
          #'(ap e ...))]
       [x new-id]))))

(define-syntax (let-immutable stx)
  (syntax-case stx ()
    [(_ ([x e] ...) body ...)
     #'(let ([x e] ...)
         (let-syntax ([x (immutable-variable-transformer #'x)] ...)
           body ...))]))

On Sunday, November 5, 2017 at 5:15:24 AM UTC-5, Tony Garnock-Jones wrote:
> Would it make sense to have a `let-immutable` form that was just like 
> `let` but that forbade use of `set!` with introduced variables? 
> I'm thinking it could be handy for authors of libraries that introduce a 
> lot of bindings in DSLs where mutability has to be strictly controlled. 
> I think it is probably possible to get the effect of `let-immutable` 
> with careful use of identifier macros, but would there be advantages 
> internal to the compiler/runtime of being able to up-front, primitively 
> declare a set of bindings as immutable? 
> Tony 

You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
For more options, visit

Reply via email to