gpt4 book ai didi

clojure - 在 Clojure 中比较字符串的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-05 09:21:00 25 4
gpt4 key购买 nike

我不知道如何在 Clojure 中比较字符串。鉴于此基本功能:

(defn login [username]
(let [x (username)]
(if (identical? x "John")
"Welcome"
"incorrect username")))

我不断收到此错误消息:调用函数时无法将 java.lang.String 转换为 clojure.lang.IFn。在 Clojure 中比较字符串的最佳方式是什么?

最佳答案

您收到的错误消息是因为进入您的函数的 username 是一个字符串,而您正在尝试调用它(没有任何参数)。您实际上根本不需要 let 形式。将 x 替换为 username

所有不可变值都响应使用 =:

(= username "John")

= 实际上检查值,而不是一些“内存指针”概念。

关于clojure - 在 Clojure 中比较字符串的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35424008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com