[Cs254f11] Two annoying fiddly syntax questions

Wm. Josiah Erikson wjerikson at hampshire.edu
Wed Nov 16 15:17:01 EST 2011


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


More information about the Cs254f11 mailing list