Skip to content

String interpolation for scheme using the familiar "$" character

Notifications You must be signed in to change notification settings

gwatt/dollar-sign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dollar Sign

Add string interpolation to your R6RS scheme code with the familiar '$' or the '#' The '$' interpolator will stringify as with display while '#' will stringify as with write.

Examples:

(import (dollar-sign))

; simple case
(let ((a 1)
      (b 2)
      (c 3))
  ($"$a + $b + $c = $(+ a b c)")) => "1 + 2 + 3 = 6"

; if you want no spaces between your variable and another non-space non-parenthetical,
; wrap your variable with parentheses
(let ((a 1)
      (b 2)
      (c 3))
  ($"$(a)$(b)$(c)")) => "123"

; Dollar signs are valid parts of identifiers
(let ((a 1)
      (b 2)
      (c 3))
  ($"$a$b$c")) => error, no identifier a$b$c

; function calls:
; zero argument functions need two sets of parentheses around the interpolation
; functions with one or more arguments do not need the extra set of parentheses
(define (two) 2)
($"$((two))") => "2"
; functions that take arguments can be called either way:
($"$(+ 1 2 3 4)") => "10"
($"$((+ 1 2 3 4))") => "10"

; literal dollar signs in your string:
; put two dollar signs in a row
($"$$") => "$"
(let ((dollars 10)
      (cents 99))
  ($"$$$(dollars).$(cents)")) => "$10.99"

Examples using #:

(let ([a #\a])
  ($"#a")) => "#\\a"

(let ([a "asdf"])
  ($"#a")) => "\"asdf\""

About

String interpolation for scheme using the familiar "$" character

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages