我正在尝试以下代码:
(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
问题出在哪里,如何解决?
这与
string-substitute*
无关。
您引用的是列表,因此不会评估(string-append "NO " "TESTING")
:
> '(("a test" . (string-append "NO " "TESTING")))
'(("a test" string-append "NO " "TESTING"))
使用准报价:
`(("a test" . ,(string-append "NO " "TESTING")
或者根本不引用:
(list (cons "a test" (string-append "NO " "TESTING"))