help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice on writing predicates


From: Andreas Röhler
Subject: Re: Advice on writing predicates
Date: Fri, 26 Jun 2009 09:37:10 +0200
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

Sarir Khamsi wrote:
> 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))
>
> seems to work. I know that I don't need to save \2 and \3 but wanted
> that for a later function.

After the core question has been answered, remains: how to deliver values?

Several possibilities exist. You could return a list instead a boolean.

Or define variables outside:

(defvar value-to-preserve1 nil)
(defvar value-to-preserve2 nil)

(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)))
;;;;;;;;;;
  (setq value-to-preserve1 (nth 1 version-num))
  (setq value-to-preserve2 (nth 2 version-num))
::::::::::
  (if (> 22 (car version-num))
      t
    nil))


Cheers

Andreas


>  Any comments or suggestions on how to make
> this better? Thanks.
>
> Sarir
>
>   





reply via email to

[Prev in Thread] Current Thread [Next in Thread]