[Cs254f11] lets that depend on other things that have been let in the same context

Wm. Josiah Erikson wjerikson at hampshire.edu
Fri Dec 2 13:40:19 EST 2011


Oh. Right. Duh :)

I actually even knew that at some point, looking back earlier in my 
code. Thanks. I knew that couldn't be right - you HAVE to be able to 
define variables that depend on other variables.

     -Josiah


On 12/2/11 12:08 PM, Lee Spector wrote:
> Josiah,
>
> You just have too many brackets in there. In a "let" you can define multiple bindings, each with its own symbol and init-expression, but you should just list them all in the same single set of [] brackets. So you probably want this:
>
> (defn prediction-test
>    [psize gens]
>    (let [best-fit (evolve_best_fit psize gens)
>          reference-error (error best-fit)
>          test-error (test_error best-fit)
>          error-difference (Math/abs (- reference-error test-error))]
>      (println "The shortest best fit individual over" gens "generations with a population size of" psize)
>      (println "was" best-fit)
>      (println "It had an error of" reference-error "against the reference songs, and an error of")
>      (println test-error "against the test songs, giving a difference of" error-difference)))
>
>   -Lee
>
>
> On Dec 2, 2011, at 11:35 AM, Wm. Josiah Erikson wrote:
>
>> I find it annoying, just for readability of my program and not having to do things over and over again, that I can't do this:
>>
>> (defn prediction-test
>>   [psize gens]
>>   (let [best-fit (evolve_best_fit psize gens)]
>>     [reference-error (error best-fit)]
>>     [test-error (test_error best-fit)]
>>     [error-difference (Math/abs (- reference-error test-error))]
>>     (println "The shortest best fit individual over" gens "generations with a population size of" psize)
>>     (println "was" best-fit)
>>     (println "It had an error of" reference-error "against the reference songs, and an error of")
>>     (println test-error "against the test songs, giving a difference of" error-difference)))
>>
>> It tells me that it can't resolve the symbol reference-error in this context. I assume that this is because it defines those out of order or something. But why didn't it complain about not knowing what best-fit was first?
>>
>> Am I doing this wrong, or can you just not do this?
>>
>> -- 
>> Wm. Josiah Erikson
>> Network Engineer
>> Hampshire College
>> Amherst, MA 01002
>> (413) 559-6091
>>
>> _______________________________________________
>> Cs254f11 mailing list
>> Cs254f11 at lists.hampshire.edu
>> https://lists.hampshire.edu/mailman/listinfo/cs254f11
> --
> 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