Clojure函数中的参数

4
我有一个函数,它的功能如下:
(the-function [one] [two] [three])

我需要一个调用 the-function 的函数。
我尝试使用 [&args],但似乎无法正确地传递参数。
如果有帮助的话,the-function 就像 MySQL 中的 create-table,可以在这里找到:here 编辑: 我的不起作用的函数是这样的:
(defn my-function [& args]
   (the-function args))

我希望能够做到以下几点:

(my-function [one] [two] [three])

并使用这些参数调用the-function


我不确定你在问什么。你想让你的函数如何调用the-function? - Rayne
@Jon:你的修改使得事情更加混乱。 - missingfaktor
我非常确定这是一个愚蠢的问题,这使得正确表达它变得更加困难。 - Jon Romero
@Jon:从你的个人资料来看,Python 似乎是你的主要编程语言。试着用 Python 表达你想做的事情,我们会尝试告诉你如何在 Clojure 中实现它。 - missingfaktor
谢谢@MF!看起来答案只是一个应用程序 :) - Jon Romero
3个回答

4
好的,您需要的是这个:

好的,您想要的是这个:

(defn my-function [& args] (apply the-function args))

Apply函数将一个函数应用到一系列参数上,就好像它们是单独的参数一样。


2

apply是一个调用函数的函数,例如:

(defn add-three [x y z] (+ x y z))

(add-three 1 2 3)
(apply add-three '(1 2 3))

这有帮助吗?

0

我不确定我理解你的问题。

你需要的是解构吗?

(defn the-function [[one two three]]
  (println (str one two three)))

(defn myfunction [& args]
   (the-function args))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接