[Cs254f11] subst
Wm. Josiah Erikson
wjerikson at hampshire.edu
Fri Nov 18 14:30:51 EST 2011
Yeah, it's perfect (this isn't exactly what I'm going end up doing, but
it shows the concept). This will actually be really easy! Check it out:
critic_evolution.core=>
(use 'clojure.walk)
nil
critic_evolution.core=>
(zipmap list-of-retrieval-functions list-of-analysis-functions)
{(p_i_m) percent_in_mixolydian,
(a_v) average_velocity,
(l_c_r_n) least_common_real_note,
(p_i_l) percent_in_lydian,
(a_n) average_note,
(l_n) low_note,
(p_o_pb) percentage_of_pitchbend,
(p_i_b) percent_in_blues,
(m_c_r_n) most_common_real_note,
(n_o_d_r_n) number_of_different_real_notes,
(h_n) high_note,
(a_r_n) average_real_note,
(s_d_m) std_dev_mostcom,
(p_o_p) percentage_of_percussion,
(p_i_p) percent_in_pentatonic}
critic_evolution.core=>
(def function-lookup (zipmap list-of-retrieval-functions
list-of-analysis-functions))
#'critic_evolution.core/function-lookup
critic_evolution.core=>
(def mark (random-code 5))
#'critic_evolution.core/mark
critic_evolution.core=>
mark
(max
(-
(min (* (p_i_p) (- (l_n) (s_d_m))) (l_c_r_n))
(pmod
(n_o_d_r_n)
(pquot (* (p_i_m) (n_o_d_r_n)) (min (p_i_p) (p_o_pb)))))
(pd
(pquot
(pd (- (h_n) (p_i_l)) (- (a_v) (p_i_p)))
(pmod (pmod (l_n) (n_o_d_r_n)) (pmod (p_o_pb) (p_o_pb))))
(pmod (+ (pmod (p_i_b) 78) (pd (n_o_d_r_n) (p_o_pb))) 32)))
critic_evolution.core=>
(postwalk-replace function-lookup mark)
(max
(-
(min
(* percent_in_pentatonic (- low_note std_dev_mostcom))
least_common_real_note)
(pmod
number_of_different_real_notes
(pquot
(* percent_in_mixolydian number_of_different_real_notes)
(min percent_in_pentatonic percentage_of_pitchbend))))
(pd
(pquot
(pd
(- high_note percent_in_lydian)
(- average_velocity percent_in_pentatonic))
(pmod
(pmod low_note number_of_different_real_notes)
(pmod percentage_of_pitchbend percentage_of_pitchbend)))
(pmod
(+
(pmod percent_in_blues 78)
(pd number_of_different_real_notes percentage_of_pitchbend))
32)))
critic_evolution.core=>
On 11/18/11 2:26 PM, Wm. Josiah Erikson wrote:
> ..and if I'm reading postwalk-replace's documentation correctly, I can
> create a map of things to look for and things to replace and it will
> do all of them. From the documentation:
>
> Recursively transforms form by replacing keys in smap with their
> values. Like clojure/replace but works on any data structure. Does
> replacement at the leaves of the tree first.
>
> Source:
> (defn postwalk-replace
> "...docs..."
> {:added "1.1"}
> [smap form]
> (postwalk (fn [x] (if (contains? smap x) (smap x) x)) form))
>
> So actually postwalk-replace will do all of my work for me. Yes?
>
> -Josiah
>
>
>
> On 11/18/11 12:29 PM, Lee Spector wrote:
>> Josiah and I discussed this in person, as a way to do what he's doing
>> more simply, and I won't repeat all of our discussion here, but
>> others might find it useful for similar or different purposes.
>>
>> -Lee
>>
>> (use 'clojure.walk)
>>
>> (defn subst
>> "Returns the given list but with all instances of that (at any depth)
>> replaced with this. Read as 'subst this for that in list'. "
>> [this that lst]
>> (postwalk-replace {that this} lst))
>>
>> (subst 0 1 '(0 1 2 3 (0 1 2 3 (0 1 2 3) 0 1 2 3) 0 1 2 3))
>>
>> ; (0 0 2 3 (0 0 2 3 (0 0 2 3) 0 0 2 3) 0 0 2 3)
>>
>>
>> --
>> 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
>>
>> _______________________________________________
>> Cs254f11 mailing list
>> Cs254f11 at lists.hampshire.edu
>> https://lists.hampshire.edu/mailman/listinfo/cs254f11
>
--
Wm. Josiah Erikson
Network Engineer
Hampshire College
Amherst, MA 01002
(413) 559-6091
More information about the Cs254f11
mailing list