[Cs254f11] Several questions
Wm. Josiah Erikson
wjerikson at hampshire.edu
Tue Oct 4 09:38:02 EDT 2011
Ah! Thanks. I had tried
(if (= arg1 true) (* 1 modification) ( 0 ) )
because I thought that the "else" had to be enclosed in parentheses. But it makes sense, I guess, that if you do that, it tries to evaluate it. It's stuff like that that still has me stumped about this language.
-Josiah
On 10/3/11 7:50 PM, Lee Spector wrote:
> 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
>
--
Wm. Josiah Erikson
Network Engineer
Hampshire College
Amherst, MA 01002
(413) 559-6091
More information about the Cs254f11
mailing list