[Cs254f11] Several questions

Lee Spector lspector at hampshire.edu
Mon Oct 3 19:50:48 EDT 2011


Josiah,

The answer to the first part is simpler than you probably expected:

On Oct 3, 2011, at 6:20 PM, Wm. Josiah Erikson wrote:

> I'm sure there is a quick and easy answer to both of these questions. I'm still trying to get my chops. So I've got a function:
> 
> (defn modified_truth
> "If the first argument is literally true, as in that exact string,
>  then this function will return the second argument.
>  Otherwise, this function will return 0."
> [arg1 modification]
> (if (= arg1 true) (* 1 modification) (* 0 1)))
> 
> So the (* 0 1) is silly and is really just a way to return 0. Is there a better way to just have something that evaluates to 0? I hate wasting CPU cycles :)

The best way to write something that evaluates to 0 is: 0

So you could do:

(if (= arg1 true) (* 1 modification) 0)

Since multiplying by 1 doesn't do anything either you could do:

(if (= arg1 true) modification 0)

Comments on your second question to come later...

 -Lee

--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438



More information about the Cs254f11 mailing list