Do any lisps have a s-expression as their head, e.g. ((f 2) 3 4)? If not, why?

前端 未结 3 1910
失恋的感觉
失恋的感觉 2021-01-12 11:24

Do any lisps support nested s-expression on their head? For example

((f 2) 3 4)

for which (f 2) presumably evaluates to a fun

3条回答
  •  一整个雨季
    2021-01-12 11:36

    Lisp-1 lisps, such as Scheme, usually have all expressions of a function form evaluated, even the function itself.

    Lisp-2 lisps, such as Common Lisp, usually have different behaviour for the function and for the arguments. Whereas the arguments are evaluated, the function is looked up. The common way to invoke an evaluated function is to use funcall or apply.

    (funcall (f 2) 3 4)
    

    In Common Lisp, you can use a lambda form, if you insist on evaluating something to a function in the operator:

    ((lambda (&rest args) (apply (f 2) args)) 3 4)
    

提交回复
热议问题