On Wed, Jan 21, 2009 at 10:29 AM, Mark Volkmann
<[email protected]> wrote:
>
> What does "321" represent?

user=> (show 321 :bridge)
===  public final java.lang.Integer  ===
[32] compareTo : int (Object)
nil

321 is an Integer literal.  When 'show' sees a non-class as its first
argument, it fetchs the object's class and operates on that instead.
Hence the banner line that says "public final java.lang.Integer"

This is useful when you're not sure what class you're actually dealing
with, and are too lazy to type "(class " and ")" yourself:

user=> (show 42M "pow")
===  public java.math.BigDecimal  ===
[69] pow : BigDecimal (int)
[70] pow : BigDecimal (int,MathContext)
[76] scaleByPowerOfTen : BigDecimal (int)
nil

Look, it's a BigDecimal!  Hm, I wonder if hash-maps have a run()
method:

user=> (show {} "run")
===  public clojure.lang.PersistentArrayMap  ===
[56] run : void ()
nil

Wait, that's not a hash-map, it's an array-map.  And it does have a
run(), though I can't imagine how I'd use it.  But what about a real
hash-map, does it have any methods that take variable arguments?

user=> (show (hash-map) :varArgs)
===  public clojure.lang.PersistentArrayMap  ===
[44] invoke : Object (Object*20,Object[])
nil

There's that array-map again.  Let's try the class explicitly, then:

user=> (show clojure.lang.PersistentHashMap :varArgs)
===  public clojure.lang.PersistentHashMap  ===
[ 3] static create : PersistentHashMap (IPersistentMap,Object[])
[ 6] static create : PersistentHashMap (Object[])
[45] invoke : Object (Object*20,Object[])
nil

Ah, much better.  But that was too much to type.  Next time I'm going
to use (hash-map :a 1) instead.  Maybe it has a method that returns a
boolean:

user=> (show (hash-map :a 1) #(= (:returnType %) Boolean/TYPE))
===  public clojure.lang.PersistentHashMap  ===
[15] containsKey : boolean (Object)
[16] containsValue : boolean (Object)
[21] equals : boolean (Object)
[22] equiv : boolean (Object)
[48] isEmpty : boolean ()
nil

Oh, I wonder if that containsKey() method is public.  It's marked as
number [15], so:

user=> (show (hash-map :a 1) 15)
#<Method public boolean
clojure.lang.PersistentHashMap.containsKey(java.lang.Object)>

Good, it *is* public...  and so on...

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to