From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: Sarir Khamsi <sarir.khamsi@raytheon.com>
Subject: Re: Advice on writing predicates
Date: Fri, 26 Jun 2009 09:37:10 +0200 [thread overview]
Message-ID: <4A447AA6.6070801@easy-emacs.de> (raw)
In-Reply-To: <uhby454qg.fsf@raytheon.com>
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
>
>
next prev parent reply other threads:[~2009-06-26 7:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-25 22:27 Advice on writing predicates Sarir Khamsi
2009-06-25 23:23 ` Anselm Helbig
2009-06-29 19:18 ` chickenphat
2009-06-26 6:40 ` Daniel Pittman
2009-06-26 7:37 ` Andreas Röhler [this message]
2009-06-26 9:13 ` Pascal J. Bourguignon
2009-06-26 11:02 ` Thien-Thi Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A447AA6.6070801@easy-emacs.de \
--to=andreas.roehler@easy-emacs.de \
--cc=sarir.khamsi@raytheon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).