Hey all,
I'm having troubles figuring out how to do multiple things in the
"false" part of an if statement:
;; Too many parameters to "IF":
(if (something)
t
(do-something)
(do-something-else))
I can get around it this way:
(if (something)
t
((lambda ()
(do-something)
(do-something-else))))
Is this the accepted way of doing this kind of thing?
Thanks,
KS
On 26 Jan 2006 11:11:35 -0800, ··········@yahoo.com wrote:
>Hey all,
> I'm having troubles figuring out how to do multiple things in the
>"false" part of an if statement:
>;; Too many parameters to "IF":
>(if (something)
> t
> (do-something)
> (do-something-else))
>
>I can get around it this way:
>(if (something)
> t
> ((lambda ()
> (do-something)
> (do-something-else))))
>
>Is this the accepted way of doing this kind of thing?
No.
(if condition (progn then1 then2 ...) (progn else1 else2 ...))
From: Edi Weitz
Subject: Re: Multiple things with side-effects with if
Date:
Message-ID: <uu0bqpznk.fsf@agharta.de>
On 26 Jan 2006 11:11:35 -0800, ··········@yahoo.com wrote:
> I can get around it this way:
> (if (something)
> t
> ((lambda ()
> (do-something)
> (do-something-else))))
>
> Is this the accepted way of doing this kind of thing?
No. Try this:
(if (something)
t
(progn
(do-something)
(do-something-else)))
or
(cond ((something) t)
(t (do-something)
(do-something-else)))
Note that COND can have several clauses.
In your particular case it could be that this
(unless (something)
(do-something)
(do-something-else))
would also be OK (if you don't need the T as a return value).
Check out this book
<http://www.gigamonkeys.com/book/>
if you haven't done so already.
Cheers,
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
Edi Weitz wrote:
> On 26 Jan 2006 11:11:35 -0800, ··········@yahoo.com wrote:
>
> > I can get around it this way:
> > (if (something)
> > t
> > ((lambda ()
> > (do-something)
> > (do-something-else))))
> >
> > Is this the accepted way of doing this kind of thing?
>
> No. Try this:
>
> (if (something)
> t
> (progn
> (do-something)
> (do-something-else)))
Cool. I knew there was a way to do it...
> Check out this book
>
> <http://www.gigamonkeys.com/book/>
>
> if you haven't done so already.
Evidently I should, seeing as I'm lost since I loaned away Norvig's
tome.
Thanks, guys.
~KS
On Thu, 26 Jan 2006 20:11:35 +0100, <··········@yahoo.com> wrote:
> Hey all,
> I'm having troubles figuring out how to do multiple things in the
> "false" part of an if statement:
> ;; Too many parameters to "IF":
> (if (something)
> t
> (do-something)
> (do-something-else))
>
> I can get around it this way:
> (if (something)
> t
> ((lambda ()
> (do-something)
> (do-something-else))))
>
> Is this the accepted way of doing this kind of thing?
>
> Thanks,
> KS
>
Naw, the progn way has already been covered.
From the example though I would use unless.
(unless (something)
(do-something)
(do-something-else))
also look into when.
There is also a macro if* which is less tedious to use available from franz
(if* (something)
then
t
else
(do-something)
(do-something-else))
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/