Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

((f 2) 3 4)

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

Is it possible to have a lisp supporting such a thing? Or are there technical limitations that prohibit this/make it impractical?

like image 835
spacingissue Avatar asked Oct 16 '12 03:10

spacingissue


People also ask

What is a Lisp expression?

LISP expressions are called symbolic expressions or s-expressions. The s-expressions are composed of three valid objects, atoms, lists and strings. Any s-expression is a valid program. LISP programs run either on an interpreter or as compiled code.

Why is Lisp syntax?

The syntactic elements of the Lisp programming language are symbolic expressions, also known as s-expressions. Both programs and data are represented as s-expressions: an s-expression may be either an atom or a list. Lisp atoms are the basic syntactic units of the language and include both numbers and symbols.

Is Lisp a functional language?

Lisp, an acronym for list processing, is a functional programming language that was designed for easy manipulation of data strings. As one of the oldest programming languages still in use, Lisp offers several different dialects and has influenced the development of other languages.


1 Answers

In those Lisps, which have single namespace for variables and functions, your expression is valid. These are called Lisp-1. Scheme and Clojure are examples of such Lisps.

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

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

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

Edit: Thanks to Rainer Joswig i corrected the answer.

like image 79
Mirzhan Irkegulov Avatar answered Nov 09 '22 16:11

Mirzhan Irkegulov