[Cs254f11] Using collection items as functions

Maxwell William Fair Levit mwl10 at hampshire.edu
Fri Sep 30 13:47:45 EDT 2011



Howdy,

So I'm trying to generate random expressions by listing said expressions and
picking one at random. I'm doing it like this:

(rand-nth '(+ - * /))

Problem is, when I try to use that as a function, it doesn't work so well:

((rand-nth '(+ - * /)) 2 4)

4

This just returns the last item in the above call.

I assume that the problem is that Clojure is not recognizing the randomly chosen
element as its functional counterpart, is that whats going on? And how do I fix
it?

-Max


More information about the Cs254f11 mailing list