PasteRack.org
Paste # 41342
2015-12-14 15:13:26

Fork as a new paste.

Paste viewed 154 times.


Embed:

  1. #lang racket
  2.  
  3. (define-syntax string1 "hello")
  4. (define-syntax string2 "world")
  5.  
  6. (begin-for-syntax
  7.   (struct string-box (str)
  8.     #:mutable
  9.     #:property prop:rename-transformer
  10.     (lambda (inst)
  11.       (if (string-box-str inst)
  12.           #'string1
  13.           #'string2))))
  14. (define-syntax (string-lookup stx)
  15.   (syntax-case stx ()
  16.     [(_ id)
  17.      #`'#,(syntax-local-value #'id)]))
  18. (define-syntax (string-set! stx)
  19.   (syntax-case stx ()
  20.     [(_ box value)
  21.      (begin
  22.        (define-values (x y) (syntax-local-value/immediate #'box))
  23.        (set-string-box-str! x #'value)
  24.        #'(void))]))
  25.  
  26. (define-syntax current-str (string-box #t))
  27. (string-lookup current-str)
  28. (string-set! current-str #f)
  29. (string-lookup current-str)

=>

"hello"

"hello"