想要:如果传递函数或闭包,请调用它,否则返回输入.我正在尝试这个:
(defun ifcall (x) (if (typep x 'FUNCTION) (funcall x) (x)))
Run Code Online (Sandbox Code Playgroud)
得到"未定义的函数:X".为什么?
你的其他部分if不应该包裹在parens中.当你在parens中放入一些东西时,它将被视为一个函数调用.要返回值,只需执行
(defun ifcall (x) (if (typep x 'FUNCTION) (funcall x) x))
Run Code Online (Sandbox Code Playgroud)