On Wed, Jun 24, 2009 at 7:18 PM, Stephen C. Gilardi<squee...@mac.com> wrote: > > On Jun 24, 2009, at 7:02 PM, arasoft wrote: > >> 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? 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 addition to functions, several of Clojure's other objects are > "invokable"--they can operate successfully as the first item in a call > expression (a list in code). > > Invoking a set returns the element in the set that's = to the argument or > nil > Invoking a map returns the value in the map whose corresponding key is = to > the argument or nil > Invoking a keyword requires a map as its argument and returns the value in > the map corresponding to the key that's = to the keyword or nil > > "Being invokable" in Clojure is equivalent to implementing the IFn > interface. You can see in this diagram which objects in Clojure implement > IFn: > > http://github.com/Chouser/clojure-classes/blob/032beae497fddc426db05c7c6367c625a2dad04f/graph-w-legend.png > > (IFn is at the lower right).
For all those who want to understand how the class hierarchies map to various Clojure abstractions, I have broken down that (rather daunting) graph into separate areas in various slides from the tutorial I gave at ILC09: http://clojure.googlegroups.com/web/tutorial.pdf There you can much more clearly see how the collections, seqs, refs, and various concepts like sequential/associative/counted/reversible/metadata/callability/java collection/java interop are organized. Rich --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---