From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Pittman Newsgroups: gmane.emacs.help Subject: Re: Advice on writing predicates Date: Fri, 26 Jun 2009 16:40:43 +1000 Organization: I know I put it down here, somewhere. Message-ID: <873a9n8plg.fsf@rimspace.net> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1245999177 21613 80.91.229.12 (26 Jun 2009 06:52:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Jun 2009 06:52:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 26 08:52:50 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MK5In-0002gu-U6 for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Jun 2009 08:52:50 +0200 Original-Received: from localhost ([127.0.0.1]:60097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MK5In-0002Zt-Dz for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Jun 2009 02:52:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MK5IK-0002WX-9e for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 02:52:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MK5IF-0002Qc-4d for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 02:52:19 -0400 Original-Received: from [199.232.76.173] (port=40296 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MK5IE-0002QP-IZ for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 02:52:14 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:40508) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MK5ID-0000DE-Vg for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 02:52:14 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MK5IC-0003vG-FQ for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 02:52:12 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MK5I6-0004Sq-Fc for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 06:52:06 +0000 Original-Received: from sdcarl02.strategicdata.com.au ([203.214.67.82]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 26 Jun 2009 06:52:06 +0000 Original-Received: from daniel by sdcarl02.strategicdata.com.au with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 26 Jun 2009 06:52:06 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 29 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: sdcarl02.strategicdata.com.au User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux) Cancel-Lock: sha1:Co562z8EeYG5IougmwmyHYwsz+8= X-Detected-Operating-System: by mx20.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65541 Archived-At: Sarir Khamsi 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