help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conditionals in elisp


From: Thien-Thi Nguyen
Subject: Re: conditionals in elisp
Date: Wed, 28 Oct 2009 10:10:04 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

() "Drew Adams" <drew.adams@oracle.com>
() Tue, 27 Oct 2009 00:37:38 -0700

   Learning from examples is fine - very good, in fact. Others have already
   provided you examples, so I hope that helped. The quick and easy answer
   would have been to just give you a couple examples to learn from. You can
   evaluate each expression by typing it after `M-:' and hitting Enter.

   (if) raises an error: wrong number of arguments - 0 
   (if nil) raises an error: wrong number of args - 1
   (if nil 3)                -> nil
   (if t   3)                -> 3
   (if nil 3 4)              -> 4
   (if t   3 4)              -> 3
   (if nil 3 4 5)            -> 5
   (if t   3 4 5)            -> 3
   (if nil 3 4 5 6)          -> 6
   (if "anything but nil" 3) -> 3
   (if "nil" 3)              -> 3
   (if 99 3 "anything")      -> 3
   (if nil 3 (setq a 5) a)   -> 5

If these (nicely formatted) examples are useful, they could be added to
the documentation.

Also (to Harry Putnam): You can help avoid misunderstanding from other
list members by stating explicitly "i read the Emacs Lisp manual node
"Conditionals" and couldn't understand it".

In any case, in addition to M-:, the *scratch* buffer is also a nice
place to interact with Emacs.  There, the values of the expressions are
inserted into the buffer and so are less fleeting than the output of
M-: in the echo area.

To play:

- C-x b *scratch* RET
- M-x lisp-interaction-mode RET
- type an expression:
    (if 99 3 "anything")
- make sure cursor is immediately after the close-paren:
    (if 99 3 "anything")-!-   ;;; -!- represents the cursor
- type C-j; emacs displays evaluates the expression and inserts it;
  you see:
    (if 99 3 "anything")
    3
    -!-

Another benefit of experimenting via the *scratch* buffer is that if
something perplexes you there, it is very easy to mail the relevant
fragment when asking for help.

Overall, being explicit when asking for help is helpful to everyone.

thi




reply via email to

[Prev in Thread] Current Thread [Next in Thread]