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).The core function "ifn?" can also let you know if something is invokable:
Clojure 1.1.0-alpha-SNAPSHOT user=> (ifn? #{:a :b :c}) true user=> (ifn? 3) false user=> (fn? #{:a :b :c}) false user=> --Steve
smime.p7s
Description: S/MIME cryptographic signature