- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Lisp 的 APPLY 用于调用存储在列表中的计算参数的函数。(根据 Rainer 的评论修改)
例如,以下代码将 (list 1 2 3) 更改为 (+ 1 2 3)。
(apply #'+ '(1 2 3))
但是,Python 的 apply 做的是 Lisp 的 funcall 做的,除了一些细微的差别(输入以元组/列表的形式给出)
(defun add (x y) (+ x y))(funcall #'add 1 2) or(funcall #'(lambda (x y) (+ x y)) 10 2)
apply(lambda x,y : x+y, [1,2])
你怎么看? Lisp 的 funcall 和 Python 的 apply 之间还有更多区别吗?
最佳答案
Is there any reason why Python chose the name apply not funcall?
因为它是 Python,而不是 LISP。不需要具有相同的名称,funcall
是一个 LISP 命令,而 apply
在 Python 中是不同的东西。
apply
在 Python 中已弃用,请使用扩展的调用语法。
旧语法:
apply(foo, args, kwargs)
新语法:
foo(*args, **kwargs)
关于python - Lisp 的 apply 和 funcall 与 Python 的 apply,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3856917/
考虑这段代码: (defclass test () ((test :initform nil :accessor test))) # (defvar *test* (make-instance 'te
我被 this old answer 中的代码激怒了解释为什么需要尖锐的引用,但我不明白的是为什么 funcall 似乎跳过了通常的范围规则。 (defun test () 'red) (flet (
为什么 funcall 没有语法糖?我们非常需要它。写一些像 (do-something arg0 arg1 arg2) 而不是 (funcall do-something arg0 arg1 a
我在 lisp 中有以下功能: (defun F(F) #'(lambda (n) (if (zerop n) (funcall F n) (1+
ANSI 通用语言。为什么我在最后一个案例中得到了其他答案? (list 1 2 3 nil) ; (1 2 3 nil) (funcall (function list) 1 2 3 nil) ;
我正在尝试将一个函数作为参数传递并在另一个函数中调用该函数。 我的一段代码如下所示: (defun getmove(strategy player board printflag) (setq mov
为什么我们必须使用 funcall 来调用 Common Lisp 中的高阶函数?例如,为什么我们必须使用: (defun foo (test-func args) (funcall test-f
Common Lisp HyperSpec在funcall条目中说, (funcall function arg1 arg2 ...) == (apply function arg1 arg2 ..
根据这份文件:http://cl-cookbook.sourceforge.net/functions.html (defun adder (n) (lambda (x) (+ x n))) (f
这实际上是两个相关的问题。 绑定(bind)函数的 flet 和 let 有什么区别。 下面的示例 A 和 B 是否等效? 一种) (flet ((myfun (x) (+ x 3))) (myf
我的功能: count = 0 def fake(x): global count print count count += 1 return x ** 4 + 10
我不明白 funcall 在这个例子中会做什么。我需要有关代码何时执行的解释。 (defun total-value (field L) "Answer average value of fiel
一边检查let over lambda我碰巧遇到 (defmacro! dlambda (&rest ds) `(lambda (&rest ,g!args) (case (car ,g
为什么在 elisp 中调用 lambda 有效,但应用它会引发错误? ELISP> (funcall (lambda ())) nil ELISP> (apply (lambda ())) ***
我正在阅读一本做作业的书,我明白使用#'是将变量视为函数而不是变量。但我对FUNCALL有点模糊。我知道 lisp 从变量中生成对象,所以函数名只是一个“指针”(可能是一个坏词,但希望你明白我的意思)
Lisp 的 APPLY 用于调用存储在列表中的计算参数的函数。(根据 Rainer 的评论修改) 例如,以下代码将 (list 1 2 3) 更改为 (+ 1 2 3)。 (apply #'+ '(
我是一名优秀的程序员,十分优秀!