Scheme 从伪代码到方案

Scheme 从伪代码到方案,scheme,pseudocode,Scheme,Pseudocode,key我只给你解决方案的一般结构,因为这看起来像是家庭作业,你应该试着自己解决它: (define (key str) (let loop ((chars <???>) ; transform the string into a list of chars (acc 5381)) ; this is the initial value of the accumulator (if <???> ; if t

key我只给你解决方案的一般结构,因为这看起来像是家庭作业,你应该试着自己解决它:

(define (key str)
  (let loop ((chars <???>) ; transform the string into a list of chars
             (acc 5381))   ; this is the initial value of the accumulator
    (if <???>              ; if the list of chars is empty
        acc                ; then return the accumulator
        (loop <???>        ; otherwise advance recursion over list
              <???>))))    ; update accumulator, use `ctv` and apply the formula
最后,不要忘记测试它,如下所示:

(key "day")
=> 193381411

到目前为止你试过什么?发布代码,同时发布带有预期输出的示例输入。示例为key(“day”)=33*(33*(33*5381+ctv(
d'))+ctv(
a'))+ctv(`y')=193381411。我试图实现一个循环,但我对scheme还不太熟悉,我不理解语法,很感谢大家的帮助,是的,这是hw,但我很感谢起点,应该有很多帮助
(define key(lambda(w)(let loop((chars list w>);将字符串转换成一个字符列表(acc 5381));这是累加器的初始值(如果;如果字符列表为空acc;则返回累加器(循环;否则将递归推进列表)))
到目前为止,这看起来是否正确。我对递归部分感到困惑,我只是在列表上循环还是必须再次调用键函数?小心使用
,这些不是要使用的,它们只是占位符!。当调用
循环时,必须1)将递归推进列表,并2)更新累加器。这是有趣的部分,我敦促你自己解决它
(key "day")
=> 193381411