To expand a little on what Some Buddy replied, and make more explicit something he didn't quite say
outright about one of (cond)'s benefits:
When you have more than one possibility to check, a big advantage of (cond) over (if) is that (cond)
*doesn't even bother to look at* any conditions after the first one that is satisfied. If you check
for multiple conditions with multiple (if) functions, like this:
{code}
(if (= color "red") (...do the red thing...))
(if (= color "yellow") (...do the yellow thing...))
(if (= color "green") (...do the greeb thing...))
(if (= color "blue") (...do the blue thing...))
{code}
it will work, but it will test for *all* of those possibilities, regardless of whether it finds any
of them satisfied. If the color is "red," it will do the red thing, but then it will also, and
unnecessarily, go on to check whether the color is any of those other possibilities. That will be a
complete waste, because none of them are going to be satisfied if the color is "red."
But if you use (cond), like this:
{code}
(cond
((= color "red") (...do the red thing...))
((= color "yellow") (...do the yellow thing...))
((= color "green") (...do the green thing...))
((= color "blue") (...do the blue thing...))
(T (...do the anything-else thing)); [with or without this]
); end cond
{code}
then it will only check *until it finds a true condition*, and ignore the rest. If the color is
"red," it will do the red thing, and then *go to the end* of the (cond) function, and continue with
whatever is next, without bothering itself to check for the other possibilities which won't be
satisfied.
Also, if you want an anything-else thing to be done if the color isn't any of those four, then it's
a lot more complicated with (if) functions. You would probably need an additional (if) function,
along with the ones above, something like:
{code}
(if
(not
(or
(= color "red")
(= color "yellow")
(= color "green")
(= color "blue")
); end or
); end not
(...do the anything-else thing)
)
{code}
or, a somewhat shorter way:
{code}
(if
(not
(member color '("red" "yellow" "green" "blue"))
)
(...do the anything-else thing)
)
{code}
Shorter, but still a lot more code than necessary if you use the (cond) approach instead.
--
Kent Cooper
"djohnson" wrote...
.... the if/cond are still confusing to me but I will come
around.
....