如何使用函数作为参数并应用于lisp中的子列表?

Dee*_*pak 1 lisp clisp common-lisp

问题很简短.

假设F是任何函数,在这种情况下我使用F= length,并且L是包含子列表的任何列表,例如L在这种情况下是((3 3 3) (2 2) (1)).如何将功能F应用于列表车L

(defun try (F L)
    ('F (car L)))
Run Code Online (Sandbox Code Playgroud)

当我把这个函数称为

(try 'length '((3 3 3) (2 2) (1) (1) ))
Run Code Online (Sandbox Code Playgroud)

我应该得到3的,因为第一Ssblist长度的结果L,(3 3 3)是3.

Chr*_*ung 6

用途funcall:

(funcall f (car l))
Run Code Online (Sandbox Code Playgroud)