开发者

Why do many lisps have function names like "foo", "foo-1", "foo-2", etc.?

开发者 https://www.devze.com 2023-04-11 06:18 出处:网络
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

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, and macroexpand-1 that expands only the top-level macro
  • there's a common (not standardized) utility last1, that returns the last element of a list (as last returns the last cons cell)
  • the case for prin1 is more complicated, but as well isn't just a random addition of 1: there's print, princ and prin1 (and also pprint). See Hyperspec for more details.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号