Difference between sexp and list in Emacs?

Emacs has commands for moving the cursor over expressions enclosed in parentheses (or any parentheses), namely forward-sexp, backward-sexp, forward-list and backward-list. In Lisp and any other code, they behave the same, so I do not see the difference between * -sexp and * -list, except that the latter do not work inside comments or quotes.

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

Just in case, I understand the up-list and down-list commands, they are not related to the topic.

+4
source share
2 answers

A list is one example of an s-expression, so any function that works with s-expressions should work on lists (but not necessarily the other way around, since there are also non-list sexps).

The elisp manual says:

An A Lisp object for evaluation is called a "form" or "Expression" (1). The fact that forms are data objects, and not just text, is one of the fundamental differences between Lisp-like languages ​​and typical programming languages. Any object can be evaluated, but in Practical only numbers, characters, lists and lines are evaluated very often.

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

(1) It is sometimes also called the "S-expression" or "sexp", but we usually do not use this terminology in this manual.

Ch i g (elisp) Intro Eval RET

+4
source

Not all s-expressions are lists, for example. s-expressions are variables, while they are not explicitly lists.

Consider the following example:

 foo (bar) 

If you put a dot at the beginning of a line, forward-sexp move the dot to the end of "foo", and forward-list move the dot to the end of "(bar)"

+4
source

All Articles