Any fox has an s-expression in the form of a head, for example. ((f 2) 3 4)? If not, why?

Do any lisps help support nested s-expressions on the head? for example

((f 2) 3 4) 

for which (f 2) presumably evaluates the function / macro to apply at 3 4 .

Is it possible to support lisp such a thing? Or are there technical limitations that prohibit this / make it inappropriate?

+7
source share
3 answers

In those Lisps that have a single namespace for variables and functions, your expression is valid. They are called Lisp -1. Schemes and Clojure are examples of such Lisps.

In those Lisp that have separate namespaces for variables and functions, your expression will be (funcall (f 2) 3 4) . They are called Lisp -2. Common Lisp and Emacs Lisp are examples of such Lisps.

In Lisp -2, each character has a value slot and a functional slot. To call a function that is stored in a value slot, you need to use the funcall keyword .

More on this issue: http://www.dreamsongs.com/Separation.html

Edit: Thanks to Rainer Joswig, I fixed the answer.

+12
source

For example, in Common Lisp above is not valid. Common Lisp syntax usually does not allow lists as the head of a function call. You must use FUNCALL to call the return value of the function.

 (funcall (f 2) 3 4) 

Some other Lisp dialects allow this. A circuit is such a dialect of Lisp. The circuit also evaluates the head of the function expression.

+5
source

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

Lisp -2 lisps, such as Common Lisp, usually have different behavior for function and arguments. While the arguments are evaluated, the function is scanned. A common way to call 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 in a statement:

 ((lambda (&rest args) (apply (f 2) args)) 3 4) 
+1
source

All Articles