From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: Advice on writing predicates Date: Fri, 26 Jun 2009 09:37:10 +0200 Message-ID: <4A447AA6.6070801@easy-emacs.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1246001725 28118 80.91.229.12 (26 Jun 2009 07:35:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Jun 2009 07:35:25 +0000 (UTC) To: Sarir Khamsi Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 26 09:35:18 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 1MK5xt-00012m-HB for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Jun 2009 09:35:17 +0200 Original-Received: from localhost ([127.0.0.1]:46396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MK5xs-0004U8-NE for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Jun 2009 03:35:16 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MK5xZ-0004Sf-Od for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 03:34:57 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MK5xU-0004PY-9I for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 03:34:56 -0400 Original-Received: from [199.232.76.173] (port=44746 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MK5xU-0004PV-4O for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 03:34:52 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:42960) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MK5xT-0000l4-Ng for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 03:34:51 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.187]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MK5xS-0006OM-UO for help-gnu-emacs@gnu.org; Fri, 26 Jun 2009 03:34:51 -0400 Original-Received: from [192.168.178.27] (p54BE9433.dip0.t-ipconnect.de [84.190.148.51]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MKv5w-1MK5xO2Xwp-000LAh; Fri, 26 Jun 2009 09:34:48 +0200 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: X-Provags-ID: V01U2FsdGVkX18Iltfi8vWPKztBgRswKf9nOKiGYd6lI/8MVTs 4nVLIGNcITK54eO1Qa1ys0Pg+3IH7zEwjCJPjCNDPhDBTXA3MU Y6BKLiB7xRA6g+KSxaUeafIZFus9Ndpfu5MYyeqImI= X-Detected-Operating-System: by mx20.gnu.org: Genre and OS details not recognized. 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:65543 Archived-At: 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 > >