Welcome to the CHICKEN Scheme pasting service

Code to replace $[foo} in arbitrary strings with foo from a hash-table added by alaricsp on Sun Jun 26 22:23:18 2016


(define (interpolate location *vars* text)
  (irregex-replace/all
   (irregex '(seq "${" (=> expr (+ (~ ("}")))) "}"))
   text
   (lambda (m)
     (let ((expr (irregex-match-substring m 'expr)))
       (cond
        ((string=? expr "$")
         "$")
        ((hash-table-exists? *vars* expr)
         (hash-table-ref *vars* expr))
        (else
         (error (sprintf "Undefined variable ${~a} in ~a" expr location))))))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the result of `(let ((- +)) (- 4 3 8))'?
Visually impaired? Let me spell it for you (wav file) download WAV