Created
March 4, 2019 20:30
-
-
Save rain-1/72c01581744c765843fd70ecf79cf5b4 to your computer and use it in GitHub Desktop.
generalized set! in racket - failed idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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