[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Advice on writing predicates
From: |
Daniel Pittman |
Subject: |
Re: Advice on writing predicates |
Date: |
Fri, 26 Jun 2009 16:40:43 +1000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux) |
Sarir Khamsi <sarir.khamsi@raytheon.com> writes:
> I wrote a simple predicate that returns t if the Emacs major version number
> is greater than 22 and would like some advice/comments:
>
> The following
>
> (defun sk-emacs-version-greater-than23-p ()
> "Return non-nil if current Emacs version is greater than 22."
> (interactive)
> (setq version-string (replace-regexp-in-string
> ".*?\\([0-9]+\\)\.\\([0-9]+\\)\.\\([0-9]+\\)[()-.a-zA-Z0-9 \n]+" "\\1 \\2
> \\3" (emacs-version)))
> (setq version-num (mapcar 'string-to-number (split-string version-string)))
> (if (> 22 (car version-num))
> t
> nil))
(defun dp/emacs-version-greater-than-23-p ()
"REVISIT: Document me, you fool!"
(interactive)
(> (string-to-number (car (split-string emacs-version "\\."))) 23))
That does two things better: first, it uses the emacs-version variable which
just holds the version number.
Second, it doesn't bother with a specific true value, just a generic one,
which the '>' function happily returns.
Regards,
Daniel