[Cs254f11] Simple question - def and concat

Wm. Josiah Erikson wjerikson at hampshire.edu
Wed Oct 19 11:21:03 EDT 2011


You could create a vector of melodies instead, sticking the created 
melody into a different position in the vector each time through the loop.
    -Josiah


Jesse French wrote:
> Hi all, very simple question related to this function:
>
> (defn new-pop
>   [popsize length]
>   (loop [loopcount 1]
>     (if (< loopcount popsize)
>       (def melody (new-melody length))
>       (recur (inc loopcount)))))
>
> This works, but I'd like to def a different "melody (new-melody length)" each time. Basically, each run through the loop should create a unique melody with a unique name - my hope was to just name it 'melody' with the count appended.
>
> My first thought was to do this:
>
>       (def (concat "melody" (loopcount)  (new-melody length))
>
> But I am running into problems each time I try a different way. One obvious problem is the different data types involved, but even if I pass it a working concat statement def will not accept a statement that begins this way.
>
> Any ideas for getting around this?
>
> Thanks,
> Jesse
>
> _______________________________________________
> 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



More information about the Cs254f11 mailing list