* if/else execution in elisp
@ 2002-10-17 13:08 ken
0 siblings, 0 replies; 6+ messages in thread
From: ken @ 2002-10-17 13:08 UTC (permalink / raw)
This should be simple. It is in every other language I've ever used.
Here's an if/else:
(if (> lb 5)
(setq hh (+ 2 hh) lb (+ 4 lb)) ; if true
(setq hh (+ 1 hh) lb (+ 3 lb)) ; if false
)
What I'm trying to do should be obvious. If not:
If lb is greater than 5, increment hh and lb by 2 and 4 respectively.
If not, increment hh and lb by 1 and 3 respectively.
Appreciated.
--
AMD crashes? See http://cleveland.lug.net/~ken/amd-problem/.
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.1034973328.14861.help-gnu-emacs@gnu.org>]
* Re: if/else execution in elisp
[not found] <mailman.1034973328.14861.help-gnu-emacs@gnu.org>
@ 2002-10-18 20:43 ` Barry Margolin
2002-10-20 19:36 ` ken
0 siblings, 1 reply; 6+ messages in thread
From: Barry Margolin @ 2002-10-18 20:43 UTC (permalink / raw)
In article <mailman.1034973328.14861.help-gnu-emacs@gnu.org>,
ken <ken@cleveland.lug.net> wrote:
>This should be simple. It is in every other language I've ever used.
>Here's an if/else:
>
> (if (> lb 5)
> (setq hh (+ 2 hh) lb (+ 4 lb)) ; if true
> (setq hh (+ 1 hh) lb (+ 3 lb)) ; if false
> )
>
>What I'm trying to do should be obvious. If not:
>
>If lb is greater than 5, increment hh and lb by 2 and 4 respectively.
>If not, increment hh and lb by 1 and 3 respectively.
It looks correct to me. What's the problem you're having?
--
Barry Margolin, barmar@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: if/else execution in elisp
2002-10-18 20:43 ` Barry Margolin
@ 2002-10-20 19:36 ` ken
2002-10-20 21:35 ` Ehud Karni
[not found] ` <mailman.1035149738.4225.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: ken @ 2002-10-20 19:36 UTC (permalink / raw)
Cc: help-gnu-emacs
Thanks for the vote of confidence. I was starting to doubt reality.
Here's the bigger fragment:
(defun testo-func ()
(setq
zlist '(2 65535 3)
firsto (car zlist)
segundo (car (cdr zlist))
thirdo (cdr (cdr zlist)))
(if (> segundo 44671)
(setq firsto (+ 2 firsto) segundo (- 44672 segundo))
(setq firsto (+ 1 firsto) segundo (+ 20864 segundo))
)
(list firsto segundo thirdo)
)
When I evaluate (test-func), I want to get (4 20863 3), but I'm getting
instead (4 -20863 (3)). The hilarious part is that testo-func works
just fine for a lot of setq'd values.
I'm about to die laughing. Please help it stop.
ken
--
AMD crashes? See http://cleveland.lug.net/~ken/amd-problem/.
Spake Barry Margolin at 20:43 (UTC-0000) on Fri, 18 Oct 2002:
= In article <mailman.1034973328.14861.help-gnu-emacs@gnu.org>,
= ken <ken@cleveland.lug.net> wrote:
= >This should be simple. It is in every other language I've ever used.
= >Here's an if/else:
= >
= > (if (> lb 5)
= > (setq hh (+ 2 hh) lb (+ 4 lb)) ; if true
= > (setq hh (+ 1 hh) lb (+ 3 lb)) ; if false
= > )
= >
= >What I'm trying to do should be obvious. If not:
= >
= >If lb is greater than 5, increment hh and lb by 2 and 4 respectively.
= >If not, increment hh and lb by 1 and 3 respectively.
=
= It looks correct to me. What's the problem you're having?
=
=
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: if/else execution in elisp
2002-10-20 19:36 ` ken
@ 2002-10-20 21:35 ` Ehud Karni
[not found] ` <mailman.1035149738.4225.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 6+ messages in thread
From: Ehud Karni @ 2002-10-20 21:35 UTC (permalink / raw)
Cc: help-gnu-emacs
On Sun, 20 Oct 2002 15:36:03 -0400 (EDT), ken <ken@cleveland.lug.net> wrote:
>
> (defun testo-func ()
> (setq
> zlist '(2 65535 3)
> firsto (car zlist)
> segundo (car (cdr zlist))
> thirdo (cdr (cdr zlist)))
This should be:
thirdo (car (cdr (cdr zlist))))
>
> (if (> segundo 44671)
> (setq firsto (+ 2 firsto) segundo (- 44672 segundo))
The correct expression is: segundo (- segundo 44672))
> (setq firsto (+ 1 firsto) segundo (+ 20864 segundo))
> )
> (list firsto segundo thirdo)
> )
Now it works as you expect.
I suggest the use of the `nth' built-in function (check its help)
for getting the nth element of a list, instead of `(car (cdr ...'
Ehud.
--
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
mailto:ehud@unix.mvs.co.il Better Safe Than Sorry
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.1035149738.4225.help-gnu-emacs@gnu.org>]
* Re: if/else execution in elisp
[not found] ` <mailman.1035149738.4225.help-gnu-emacs@gnu.org>
@ 2002-10-21 20:10 ` Barry Margolin
2002-10-22 4:51 ` Miles Bader
0 siblings, 1 reply; 6+ messages in thread
From: Barry Margolin @ 2002-10-21 20:10 UTC (permalink / raw)
In article <mailman.1035149738.4225.help-gnu-emacs@gnu.org>,
Ehud Karni <ehud@unix.mvs.co.il> wrote:
>I suggest the use of the `nth' built-in function (check its help)
>for getting the nth element of a list, instead of `(car (cdr ...'
Or 'first', 'second', and 'third'.
--
Barry Margolin, barmar@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-10-22 4:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-17 13:08 if/else execution in elisp ken
[not found] <mailman.1034973328.14861.help-gnu-emacs@gnu.org>
2002-10-18 20:43 ` Barry Margolin
2002-10-20 19:36 ` ken
2002-10-20 21:35 ` Ehud Karni
[not found] ` <mailman.1035149738.4225.help-gnu-emacs@gnu.org>
2002-10-21 20:10 ` Barry Margolin
2002-10-22 4:51 ` Miles Bader
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).