-1

I am trying following code:

(require-extension srfi-13)
(require-extension regex)
(print (string-substitute* "This is a test" '(("a test" . "NO TESTING ZONE" ) ) ) )

It works, with following output:

This is NO TESTING ZONE

But following does not work:

(print (string-substitute* "This is a test" '(("a test" . (string-append "NO " "TESTING") ) ) ) )

Following is the error:

Error: (string-substitute) bad argument type - not a string: (string-append "NO " "TESTING")

Even though, following shows that the output is indeed a string:

(print (string? (string-append "NO " "TESTING")))
#t

Where is the problem and how can this be solved?

rnso
  • 23,686
  • 25
  • 112
  • 234

1 Answers1

3

This has nothing to do with string-substitute*.

You're quoting the list, so (string-append "NO " "TESTING") is not evaluated:

> '(("a test" . (string-append "NO " "TESTING")))
'(("a test" string-append "NO " "TESTING"))

Use quasiquote:

`(("a test" . ,(string-append "NO " "TESTING")

or don't quote at all:

(list (cons "a test" (string-append "NO " "TESTING"))
molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • Why this does not work: `(print (string-substitute* "this is a test" (list (list "a test" "NO TESTING ZONE" ) (list "this" "THIS"))))` – rnso Apr 09 '17 at 17:17
  • @rnso Because it wants a list of pairs where both the car and the cdr are strings, not ones where the car is a string and the cdr is a list. – molbdnilo Apr 09 '17 at 22:21