我在网上找到了一个关于Scheme的简短介绍,我在使用这个功能时遇到了一些麻烦:
(define (title-style str)
(let loop ((lc #\space) (i 0) (c (string-ref str 0)))
((if (char=? lc #\space)
(string-set! str i (char-upcase c)))
(if (= (- (string-length str) 1) i)
str
(loop c (+ i 1) (string-ref str (+ i 1)))))))
(display "star wars iv: a new hope")
(display (title-style "star wars iv: a new hope"))
当我尝试调用它时,我得到了这个:
Error: call of non-procedure: #<unspecified>
Call history:
title-style.scm:6: loop
...
title-style.scm:1: g6 <--
该错误来自 Chicken Scheme,我在 Chez Scheme 中也得到了相同的结果。
它将字符串转换为标题大小写,并且根据我之前收到的错误消息,它确实:call of non-procedure: "Star Wars Iv: A New Hope"