Emacs-Lisp 比较方法的疑惑

在学习 Steve Purcell 的 Emacs 配置的时候,在 init.el 文件的中有一行代码不理解:

(let ((minver "24.3"))
  (when (version< emacs-version minver)
    (error "Your Emacs is too old -- this config requires v%s or higher" minver)))

此处的 version<(version< emacs-version minver) 是如何工作的?

version< is a compiled Lisp function in ‘subr.el’.

(version< V1 V2)

Return t if version V1 is lower (older) than V2.

Note that version string “1” is equal to “1.0”, “1.0.0”, “1.0.0.0”, etc. That is, the trailing ".0"s are insignificant. Also, version string “1” is higher (newer) than “1pre”, which is higher than “1beta”, which is higher than “1alpha”, which is higher than “1snapshot”. Also, “-GIT”, “-CVS” and “-NNN” are treated as snapshot versions.

C-h f version<

(defun version< (v1 v2)
  "Return t if version V1 is lower (older) than V2.

Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\",
etc.  That is, the trailing \".0\"s are insignificant.  Also, version
string \"1\" is higher (newer) than \"1pre\", which is higher than \"1beta\",
which is higher than \"1alpha\", which is higher than \"1snapshot\".
Also, \"-GIT\", \"-CVS\" and \"-NNN\" are treated as snapshot versions."
  (version-list-< (version-to-list v1) (version-to-list v2)))

(defun version-list-< (l1 l2)
  "Return t if L1, a list specification of a version, is lower than L2.

Note that a version specified by the list (1) is equal to (1 0),
\(1 0 0), (1 0 0 0), etc.  That is, the trailing zeros are insignificant.
Also, a version given by the list (1) is higher than (1 -1), which in
turn is higher than (1 -2), which is higher than (1 -3)."
  (while (and l1 l2 (= (car l1) (car l2)))
    (setq l1 (cdr l1)
          l2 (cdr l2)))
  (cond
   ;; l1 not null and l2 not null
   ((and l1 l2) (< (car l1) (car l2)))
   ;; l1 null and l2 null         ==> l1 length = l2 length
   ((and (null l1) (null l2)) nil)
   ;; l1 not null and l2 null     ==> l1 length > l2 length
   (l1 (< (version-list-not-zero l1) 0))
   ;; l1 null and l2 not null     ==> l2 length > l1 length
   (t  (< 0 (version-list-not-zero l2)))))
(defun version-list-not-zero (lst)
  "Return the first non-zero element of LST, which is a list of integers.

If all LST elements are zeros or LST is nil, return zero."
  (while (and lst (zerop (car lst)))
    (setq lst (cdr lst)))
  (if lst
      (car lst)
    ;; there is no element different of zero
    0))
and is a special form in ‘C source code’.

(and CONDITIONS...)

Eval args until one of them yields nil, then return nil.
The remaining args are not evalled at all.
If no arg yields nil, return the last arg’s value.


< is a built-in function in ‘C source code’.

(< NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS)

Return t if each arg (a number or marker), is less than the next arg.

setq is a special form in ‘C source code’.

(setq [SYM VAL]...)

Set each SYM to the value of its VAL.
The symbols SYM are variables; they are literal (not evaluated).
The values VAL are expressions; they are evaluated.
Thus, (setq x (1+ y)) sets ‘x’ to the value of ‘(1+ y)’.
The second VAL is not computed until after the first SYM is set, and so on;
each VAL can use the new value of variables set earlier in the ‘setq’.
The return value of the ‘setq’ form is the value of the last VAL.

M-x info

C-s elisp

等你用自己的方式看一些elisp 并 试验一些elisp代码

你就能给别人贴代码了