From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tomas@tuxteam.de Newsgroups: gmane.emacs.help Subject: Re: conditionals in elisp Date: Tue, 27 Oct 2009 06:50:04 +0100 Message-ID: <20091027055004.GA5184@tomas> References: <87iqe1og0i.fsf@newsguy.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1256622462 25451 80.91.229.12 (27 Oct 2009 05:47:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 Oct 2009 05:47:42 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Harry Putnam Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 27 06:47:35 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 1N2eu6-0005nK-HZ for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Oct 2009 06:47:34 +0100 Original-Received: from localhost ([127.0.0.1]:60837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2eu5-00084o-KD for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Oct 2009 01:47:33 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2etR-00081T-G9 for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 01:46:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2etM-0007v6-G9 for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 01:46:52 -0400 Original-Received: from [199.232.76.173] (port=39750 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2etM-0007v0-Ap for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 01:46:48 -0400 Original-Received: from alextrapp1.equinoxe.de ([217.22.192.104]:40502 helo=www.elogos.de) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2etL-0004tS-Rm for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 01:46:48 -0400 Original-Received: by www.elogos.de (Postfix, from userid 1000) id BB86B90008; Tue, 27 Oct 2009 06:50:04 +0100 (CET) Content-Disposition: inline In-Reply-To: <87iqe1og0i.fsf@newsguy.com> User-Agent: Mutt/1.5.15+20070412 (2007-04-11) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:69266 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, Oct 26, 2009 at 07:08:13PM -0500, Harry Putnam wrote: > I'm hoping someone will be kind enough to demonstrate a couple of > brief conditionals in elisp... if and if else. While the other posters sound harsh, they just are trying to provide you with some fishing rods, instead of the fish you asked for (sorry, I couldn't resist). Lest you starve in the process, and because I have the suspicion that there is just a little specific tangle between you and the docs, here is a fish (with a bit of fishing line attached to it): in Lisp, everithing is an expression. There are no "statements", as you might be accustomed to from other languages. All those "control staatements" are just expressions. If looks like that: (if lunchtime (eat fish) (work this) (work that) (procrastinate a-bit)) The meaning of that is: if the value of the variable "lunchtime" can be interpreted as "true" (i.e. is not nil), evalate the first expression (i.e. (eat fish). Otherwise evaluate the sequence coming after that (i.e. first (work this) and so on). The whole thing returns a value (you don't really say that in Lisp world: you rather say "the if expression evaluates to"). This is the value of (eat fish) in the first case, the value of the last expression in the else part (i.e. (procrastinate a-bit)= =20 in the second case. =20 Of course you may replace the variable lunchtime by a more grown-up expression: (if (eq (current-time) 'lunchtime) (whatever) (others)) If you want to do more work than one expression, have a look at prog1 and progn, which allow you to wrap a whole sequence of expressions in one. Of course, the pointers given to you in this thread are all very valuable. Especially, the tutorials by Xah mentioned will take you much further than this, and peeking into all the sources provided with Emacs can't be substituted by any well meaning post. Regards - -- tom=C3=A1s -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFK5ooMBcgs9XrR2kYRAogWAJoChrDGFCWUpQvfqzcEUAYddO13MQCeJbkZ vUsrlFC4J3iJ2sP9aHCPQcA=3D =3Deocn -----END PGP SIGNATURE-----