[Cs254f11] Two annoying fiddly syntax questions

Wm. Josiah Erikson wjerikson at hampshire.edu
Wed Nov 16 16:08:00 EST 2011


Sweet! That made it easy to do exactly what I want to do, which then 
made it easy to figure out what I broke.

I'd be psyched to have a bigger conversation about alternative 
approaches, too, but here's what broke in my evolution, and I wonder if 
anybody has any tips about tools to use to fix it.

I'm still using Lee's original inject and extract functions from before 
the multiple-arities version. They are what broke. This is because my 
individuals look like this now:

(+
  (+
   (get term-map 'most_common_real_note)
   (-
    (*
     (get term-map 'average_note)
     (pd (get term-map 'average_real_note) 63))
    (pmod
     (- (get term-map 'average_velocity) 28)
     (get term-map 'average_velocity))))
  (get term-map 'average_velocity))

Which means that (get term-map 'average_velocity) is actually a 
terminal, and should be treated as if it said "37" or something. Even if 
I was using keywords, it would still look like (:average_velocity 
term-map), which would still cause problems with the current inject and 
extract functions. Here's an example, where mark is currently defined as 
the code above:

(inject (random-code 2) mark)
(+
  (+
   (get term-map 35)
   (-
    (*
     (get term-map 'average_note)
     (pd (get term-map 'average_real_note) 63))
    (pmod
     (- (get term-map 'average_velocity) 28)
     (get term-map 'average_velocity))))
  (get term-map 'average_velocity))

...and "get term-map 35" will return an Index Out of Bounds error, 
because term-map isn't that big.

So clearly I need to write inject and extract functions that see 
anything from "get" to the next close-paran as a single entity. Any 
ideas for tools to make this easier to write? Is Lee's newer code going 
to just fix it and I should start using that instead? It doesn't look 
like it to me. The codesize function will still be broken too, I just 
realized...

Perhaps I should just rethink everything about how I'm doing this, again :)

I could write new functions that were basically duplicates of high_note 
etc that depended on term-map being set and just pulled the appropriate 
value out, and those functions would be my terminals. This is probably 
easier, isn't it? Yeah probably... no definitely :)

Sending this to the list anyway in case anybody else is going through a 
similar thought process and will find this at all helpful, or if 
somebody wants to say "No, I have the perfect solution! You should do it 
this other way!"

Thanks,
     -Josiah




On 11/16/11 3:28 PM, Lee Spector wrote:
> Josiah,
>
> I think that the answer to your first question is just: concat
>
> For the second one, we could have a long discussion about alternative approaches to do what you're really trying to do... BUT, more simply, for now, I'll not that 'foo is just reader macro syntax for (quote foo), and that that means that this might serve your purposes:
>
> (defn return-call
>   "Takes a key and returns the code necessary to get the value that corresponds to that key from term-map"
>   [key]
>   (list 'get 'term-map (list 'quote key)))
>
>   -Lee
>
>
> On Nov 16, 2011, at 3:17 PM, Wm. Josiah Erikson wrote:
>
>> I have two lists. I want to stick them together so that I can rand-nth from the resulting stuck-together list. conj doesn't work. I don't want to repeately use cons because it gets awkward and hard to read. Example:
>>
>> critic_evolution.core=>
>> a
>> ((get term-map std_dev_mostcom)
>> (get term-map high_note)
>> (get term-map low_note)
>> (get term-map average_note)
>> (get term-map average_real_note)
>> (get term-map most_common_real_note)
>> (get term-map number_of_different_real_notes)
>> (get term-map average_velocity))
>>
>> critic_evolution.core=>
>> b
>> ((rand-int 127) (rand-int 127) (rand-int 127))
>>
>> critic_evolution.core=>
>> (conj a b)
>> (((rand-int 127) (rand-int 127) (rand-int 127))
>> (get term-map std_dev_mostcom)
>> (get term-map high_note)
>> (get term-map low_note)
>> (get term-map average_note)
>> (get term-map average_real_note)
>> (get term-map most_common_real_note)
>> (get term-map number_of_different_real_notes)
>> (get term-map average_velocity))
>>
>> critic_evolution.core=>
>>
>> That's not a stuck-together list. That's a list of two things, a and b. Lame. I could have just done:
>>
>> critic_evolution.core=>
>> (list a b)
>> (((get term-map std_dev_mostcom)
>>   (get term-map high_note)
>>   (get term-map low_note)
>>   (get term-map average_note)
>>   (get term-map average_real_note)
>>   (get term-map most_common_real_note)
>>   (get term-map number_of_different_real_notes)
>>   (get term-map average_velocity))
>> ((rand-int 127) (rand-int 127) (rand-int 127)))
>>
>> and gotten the exact same thing. There must be a function that actually unwraps two lists, puts them together, and returns a single list.
>>
>> Two:
>>
>> What I really want that first list, a, to look like, is this:
>>
>> ((get term-map 'std_dev_mostcom)
>> (get term-map 'high_note)
>> (get term-map 'low_note)
>> (get term-map 'average_note)
>> (get term-map 'average_real_note)
>> (get term-map 'most_common_real_note)
>> (get term-map 'number_of_different_real_notes)
>> (get term-map 'average_velocity))
>>
>> The way I create that list, to make sure I don't have to change things in more than one place, is from a list of functions, like this:
>>
>> (map return-call list-of-functions)
>>
>> return-call is a function I wrote, that looks like this:
>>
>> (defn return-call
>>   "Takes a key and returns the code necessary to get the value that corresponds to that key from term-map"
>>   [key]
>>   (list 'get 'term-map key))
>>
>> How can I make return-call return a string that will evaluate key and get its value but also put a ' in front of it? I can't figure out how to do that.
>>
>> Thanks in advance,
>> -Josiah
>> _______________________________________________
>> 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
>


More information about the Cs254f11 mailing list