我是clojure的新手。我想通过以下方式在clojure中使用quote:
首先,我定义一个变量:
(def狗“动物”)
然后是一个函数:
(defn what-is [名称]
('name(str“是” name)))
如果我使用变量dog作为参数调用函数what-is:(what-is dog)
结果应为:
USER >>狗是动物
在这里,我返回了传递给函数what-is的参数的名称,而不是其值:
我得到的是:
是动物
这里没有提到参数狗。
同样,我要寻找的是“字面意义上的”重复传递给函数的参数的名称,如以下模板所示:
(what-is x)=> x是一个...
谢谢。
您好:我有一个句子分解为单独的单词:
["this", "is", "a", "simple", "sentence"]
Run Code Online (Sandbox Code Playgroud)
我有一份清单 indices = [0, 2, 4]
我试图将索引列表映射到句子上以返回适当索引处的单词,如下所示:如果我们应用于indices [0, 2, 4]句子,我们得到:
["this", "a", "sentence"]
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
sentence !! [x | x <- indices]
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
<interactive>:215:7: error:
• Couldn't match expected type ‘Int’ with actual type ‘[Integer]’
• In the second argument of ‘(!!)’, namely ‘[x | x <- indices]’
In the expression: tex !! [x | x <- indices]
In an equation for ‘it’: it = sentence !! [x | x <- indices
Run Code Online (Sandbox Code Playgroud)
我对使用 …