> How did you know that it delegates to 'get'?
sorry, I rushed that part.
the keyword and symbol are instances of clojure.lang.Keyword and
clojure.lang.Symbol
which are _java_ classes found in Keyword.java and Symbol.java (I
found these in the src/jvm directory)
These are what the invoke( ) methods looks like for the single and
double arity of both these classes (this is _java_ code):
/**
* Indexer implements IFn for attr access
*
* @param obj - must be IPersistentMap
* @return the value at the key or nil if not found
* @throws Exception
*/
public Object invoke(Object obj) throws Exception{
return RT.get(obj, this);
}
public Object invoke(Object obj, Object notFound) throws Exception{
return RT.get(obj, this, notFound);
}
-----------------
which in turn goes to RT.java
static public Object get(Object coll, Object key){
if(coll == null)
return null;
else if(coll instanceof Associative)
return ((Associative) coll).valAt(key);
else if(coll instanceof Map)
{
Map m = (Map) coll;
return m.get(key);
}
else if(coll instanceof IPersistentSet)
{
IPersistentSet set = (IPersistentSet) coll;
return set.get(key);
}
else if(key instanceof Number && (coll instanceof String ||
coll.getClass().isArray()))
{
int n = ((Number) key).intValue();
if(n >= 0 && n < count(coll))
return nth(coll, n);
return null;
}
return null;
}
static public Object get(Object coll, Object key, Object notFound){
if(coll == null)
return notFound;
else if(coll instanceof Associative)
return ((Associative) coll).valAt(key, notFound);
else if(coll instanceof Map)
{
Map m = (Map) coll;
if(m.containsKey(key))
return m.get(key);
return notFound;
}
else if(coll instanceof IPersistentSet)
{
IPersistentSet set = (IPersistentSet) coll;
if(set.contains(key))
return set.get(key);
return notFound;
}
else if(key instanceof Number && (coll instanceof String ||
coll.getClass().isArray()))
{
int n = ((Number) key).intValue();
return n >= 0 && n < count(coll) ? nth(coll, n) : notFound;
}
return notFound;
}
---------
all really cool....
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---