PasteRack.org
Paste # 3379
2013-10-10 16:00:42

Forked from paste # 2524.

Fork as a new paste.

Paste viewed 645 times.


Embed:

macro generated set!

  1. ;there is no built-in way to set! append in racket
  2. (define mystr "foo")
  3. (set! mystr (string-append mystr " bar"))
  4. (displayln mystr)
  5.  
  6. ;but you can create a quick macro to solve that problem
  7. (define-syntax-rule (set-append! str value)
  8.   (set! str (string-append str value)))
  9.  
  10. (define mymacrostr "foo")
  11. (set-append! mymacrostr " bar")
  12. (displayln mymacrostr)

=>

foo bar

foo bar