Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在clojure中将变量添加到字符串_Clojure - Fatal编程技术网

在clojure中将变量添加到字符串

在clojure中将变量添加到字符串,clojure,Clojure,只是教我自己clojure和四处看看: 我试图创建一个函数,它接受一个参数并将其添加到字符串中。作为一个新手,我不知道我做的是对还是错,但它不起作用。我想让它说“你好,罗恩!” 这听起来可能很基本 java.lang.RuntimeException:无法解析此文件中的符号:%s 上下文,正在编译:(无源路径:0) %1语法用于匿名函数文本,如下所示: #(str "hello, " %1) 在您的案例中,参数已命名,因此您可以直接使用它: (fn [x] (str "hello, " x "

只是教我自己clojure和四处看看:

我试图创建一个函数,它接受一个参数并将其添加到字符串中。作为一个新手,我不知道我做的是对还是错,但它不起作用。我想让它说“你好,罗恩!”

这听起来可能很基本

java.lang.RuntimeException:无法解析此文件中的符号:%s 上下文,正在编译:(无源路径:0)


%1
语法用于匿名函数文本,如下所示:

#(str "hello, " %1)
在您的案例中,参数已命名,因此您可以直接使用它:

(fn [x] (str "hello, " x "!"))
您还可以将函数本身命名为:

(defn hello [name] (str "hello, " name "!"))

%1
语法用于匿名函数文本,如下所示:

#(str "hello, " %1)
在您的案例中,参数已命名,因此您可以直接使用它:

(fn [x] (str "hello, " x "!"))
您还可以将函数本身命名为:

(defn hello [name] (str "hello, " name "!"))
您可以使用:

  • 命名函数
  • (defn hello[name](str“hello,”name“!”)
    (你好,罗恩)

  • 匿名函数
  • ((fn[name](str“hello,”name“!”)Ron)

    您可以使用:

  • 命名函数
  • (defn hello[name](str“hello,”name“!”)
    (你好,罗恩)

  • 匿名函数
  • ((fn[name](str“hello,”name“!”)Ron)


    您的回复怎么说?这肯定会告诉你的。@leongrapenthinyh我正在这样做,但我认为有一种特殊的方式连接字符串,就像java或javascript一样,你的REPL说什么?这肯定会告诉你的。@leonagrapenthinyh我正在这样做,但我认为有一种特殊的方式可以连接字符串,就像java或javascript一样,非常好。谢谢代码不太正确。后两个例子更好
    ((fn[x](str“hello,x”!)))和
    (defn hello[x](str“hello,x”!))
    。非常好。谢谢代码不太正确。后两个示例更好地
    ((fn[x](str“hello,x”!)))
    (defn hello[x](str“hello,x”!))