Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between sexp and list in Emacs?

In Emacs there are commands to move cursor across expressions delimited in parentheses (or any brackets), namely forward-sexp, backward-sexp, forward-list and backward-list. In Lisp and any other code they behave similarly, so i see no difference between *-sexp and *-list except the last do not work inside comments or quotes.

What is the functional difference between sexp and list commands, and when should i use which?

Just in case, i understand the up-list and down-list commands, they are irrelevant to the topic.

like image 476
Mirzhan Irkegulov Avatar asked Dec 26 '22 23:12

Mirzhan Irkegulov


1 Answers

A list is one example of an s-expression, so any function which operates on s-expressions should work on lists (but not necessarily vice-versa, as there are also non-list sexps).

The elisp manual says:

A Lisp object that is intended for evaluation is called a "form" or "expression"(1). The fact that forms are data objects and not merely text is one of the fundamental differences between Lisp-like languages and typical programming languages. Any object can be evaluated, but in practice only numbers, symbols, lists and strings are evaluated very often.

---------- Footnotes ----------

(1) It is sometimes also referred to as an "S-expression" or "sexp", but we generally do not use this terminology in this manual.

C-hig (elisp) Intro Eval RET

like image 108
phils Avatar answered Jan 03 '23 16:01

phils