我正在尝试以下代码:
(require-extension srfi-13)
(require-extension regex)
(print (string-substitute* "This is a test" '(("a test" . "NO TESTING ZONE" ) ) ) )
它有效,输出如下:
This is NO TESTING ZONE
但是以下不起作用:
(print (string-substitute* "This is a test" '(("a test" . (string-append "NO " "TESTING") ) ) ) )
以下是错误:
Error: (string-substitute) bad argument type - not a string: (string-append "NO " "TESTING")
尽管如下,以下表明输出确实是一个字符串:
(print (string? (string-append "NO " "TESTING")))
#t
问题出在哪里?如何解决?
答案 0 :(得分:2)
这与string-substitute*
无关。
您引用了该列表,因此未评估(string-append "NO " "TESTING")
:
> '(("a test" . (string-append "NO " "TESTING")))
'(("a test" string-append "NO " "TESTING"))
使用quasiquote:
`(("a test" . ,(string-append "NO " "TESTING")
或者根本不引用:
(list (cons "a test" (string-append "NO " "TESTING"))