PasteRack.org
Paste # 25817
2022-01-14 16:55:50

Fork as a new paste.

Paste viewed 204 times.


Embed:

Using ~a as a formatting sublanguage

  1. #lang racket
  2. (require (only-in racket/string string-join))
  3.  
  4. (define (~j s1 s2 items f)
  5.   (string-join (map (compose ~a f) items) s1 #:before-last s2))
  6.  
  7. (define name "Fred")
  8. (define age 99)
  9. (define kids '(Sally Susan Bob))
  10.  
  11. (~a "Hello, "name"! You are "age" years old, and your "
  12.     "children's names are "(~j ", " ", and " kids ~a)".")

=>

"Hello, Fred! You are 99 years old, and your children's names are Sally, Susan, and Bob."