[Cs254f11] Two annoying fiddly syntax questions

Lee Spector lspector at hampshire.edu
Wed Nov 16 15:28:07 EST 2011


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