Why do many lisps have function names like "foo", "foo-1", "foo-2", etc.?
I've noticed quite a few examples in various Lisps (at least Common Lisp and Emacs Lisp) where two or more functions had identical names except for a trailing number. For example, Emacs Lisp has eval-last-sexp
and eval-last-sexp-1
. It also has print
and prin1
. This seems to be a general practice, 开发者_C百科yet one of the first things one learns about programming is to give functions unique and descriptive names. Where does this practice come from?
Most of the times this 1 has a semantic meaning (usually, "single"):
- there's
macroexpand
that tries to expands all macros in a form, andmacroexpand-1
that expands only the top-level macro - there's a common (not standardized) utility
last1
, that returns the last element of a list (aslast
returns the last cons cell) - the case for
prin1
is more complicated, but as well isn't just a random addition of 1: there'sprint
,princ
andprin1
(and alsopprint
). See Hyperspec for more details.
精彩评论