Skip to content

Instantly share code, notes, and snippets.

@rain-1

rain-1/set.rkt

Created Mar 4, 2019
Embed
What would you like to do?
generalized set! in racket - failed idea
#lang racket
(require (for-syntax racket/syntax))
(define toplevel 'foo)
(define-syntax (set^ stx)
(syntax-case stx ()
[(_ (attr x) y)
(with-syntax ([set-attr! (format-id #'toplevel "set-~a!" (syntax-e #'attr))])
#'(set-attr! x y))]))
(define set-unbox! set-box!)
(define (t1)
(let ((b (box 3)))
(set^ (unbox b) 5)
(unbox b)))
; > (t1)
; 5
(define (t2)
(let ((b (box 3)))
(let ((set-unbox! 'blah))
(set^ (unbox b) 5)
(unbox b))))
;> (t2)
; 5
or even just use a function
(set! 'car thing value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment