> Why does this work?
>
> (take-while (complement #{\a\e\i\o\u}) "the-quick-brown-fox")
>
> When I do something similar, like
>
> (take-while (complement #(Character/isWhitespace %)) "the-quick-brown-
> fox")
>
> I have to deal with the parameter explicitly ("%"). How is the
> parameter hidden in the set/function?The set *is* a function (it implements IFn). complement accepts a function as input, so that works. Character/isWhitespace is a Java static method, which is not a first- class function, and thus can't be passed directly to complement. The #(...) syntax is shorthand for (fn [...] ...), which introduces a new anonymous function. What you've written there is equivalent to (defn whitespace? [c] (Character/isWhitespace c)) (take-while (complement whitespace?) "the quick") ... i.e., you've made a function that calls a Java static method on its input. > Could I do something like that > in my own code (not sure I'd want to, just curious what magic is at > work here)? In your Java code, implement IFn. That's the magic. In your Clojure code, just hand around functions. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
