unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: tomas@tuxteam.de
To: Harry Putnam <reader@newsguy.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: conditionals in elisp
Date: Tue, 27 Oct 2009 06:50:04 +0100	[thread overview]
Message-ID: <20091027055004.GA5184@tomas> (raw)
In-Reply-To: <87iqe1og0i.fsf@newsguy.com>

-----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) 
in the second case.
 
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ás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFK5ooMBcgs9XrR2kYRAogWAJoChrDGFCWUpQvfqzcEUAYddO13MQCeJbkZ
vUsrlFC4J3iJ2sP9aHCPQcA=
=eocn
-----END PGP SIGNATURE-----




  parent reply	other threads:[~2009-10-27  5:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-27  0:08 conditionals in elisp Harry Putnam
2009-10-27  0:25 ` Richard Riley
2009-10-27  1:03 ` Drew Adams
2009-10-27  5:33   ` Harry Putnam
2009-10-27  7:37     ` Drew Adams
2009-10-28  9:10       ` Thien-Thi Nguyen
2009-10-28 14:03         ` Drew Adams
     [not found]         ` <mailman.9621.1256738653.2239.help-gnu-emacs@gnu.org>
2009-10-28 15:42           ` LanX
2009-10-28 20:42             ` Harry Putnam
2009-10-28 16:19         ` Harry Putnam
     [not found]         ` <mailman.9630.1256746811.2239.help-gnu-emacs@gnu.org>
2009-11-02 19:31           ` Joseph Brenner
2009-10-27  5:50 ` tomas [this message]
     [not found] <mailman.9533.1256602126.2239.help-gnu-emacs@gnu.org>
2009-10-27  0:19 ` Pascal J. Bourguignon
2009-10-27  2:52 ` LanX
2009-10-27 10:36   ` Pascal J. Bourguignon
2009-10-27 12:09     ` Richard Riley
2009-10-27 17:03       ` Sean Sieger
2009-10-28 12:07         ` Richard Riley
     [not found]     ` <mailman.9555.1256645401.2239.help-gnu-emacs@gnu.org>
2009-10-27 12:31       ` Pascal J. Bourguignon
2009-10-27 13:02         ` Richard Riley
     [not found]         ` <mailman.9557.1256648714.2239.help-gnu-emacs@gnu.org>
2009-10-27 16:04           ` Pascal J. Bourguignon
2009-10-27 17:26         ` Harry Putnam
     [not found]         ` <mailman.9572.1256664440.2239.help-gnu-emacs@gnu.org>
2009-10-27 18:37           ` Pascal J. Bourguignon
2009-10-27 19:40             ` Harry Putnam
     [not found]             ` <mailman.9577.1256672457.2239.help-gnu-emacs@gnu.org>
2009-10-27 21:14               ` Pascal J. Bourguignon
2009-10-28 14:05                 ` David Kastrup
2009-10-28 15:55                   ` Harry Putnam
2009-10-28 17:45                   ` Pascal J. Bourguignon

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=20091027055004.GA5184@tomas \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=reader@newsguy.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).