[Cs254f11] Example of filter usage

Wm. Josiah Erikson wjerikson at hampshire.edu
Tue Oct 11 22:33:34 EDT 2011


True... but it was wrong. The thing that really works is:

(count(filter #(= (mod note 12) %1) (get scales scale)))

ALMOST right :) In case anyone cares.
    -Josiah


Lee Spector wrote:
> Very nice. The new version is easier to write, understand, debug, etc. And the style of thinking that it implements will bring these benefits to lots of other tasks as well...
>
>  -Lee
>
>
>
> On Oct 5, 2011, at 2:50 PM, Wm. Josiah Erikson wrote:
>
>   
>> So a light went on for me when Alec asked (probably for my benefit, thanks Alec) about filter. I was able to reduce the following code:
>>
>> (loop [i 0 result 0]
>>    (if (= i ( - (count (get scales scale)) 1))
>>    result
>>    (recur (inc i) (+ result(modified_truth (= (mod note 12) (nth (get scales scale) i) ) 1 ))))))
>>
>> to:
>>
>> (count(filter #(= (mod %1 12) note) (get scales scale)))
>>
>> Which is pretty neat.
>>
>> -- 
>> 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



More information about the Cs254f11 mailing list