- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: inspection library?
Wed, 2009-03-04, 23:17
P.S. i find myself typing exprs like these (for (m <- obj.getClass.getMethods) yield { println(m.getName); m }) at the console all the time to go wondering through code the documentation of which i either know not where it lives or do not trust to be accurate or complete or authoritative.
On Wed, Mar 4, 2009 at 2:13 PM, Meredith Gregory <lgreg.meredith@gmail.com> wrote:
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105
+1 206.650.3740
http://biosimilarity.blogspot.com
On Wed, Mar 4, 2009 at 2:13 PM, Meredith Gregory <lgreg.meredith@gmail.com> wrote:
Sir and Dam Scalahads,
Below is a bunch of silly code the purpose of which is to identify the character of a real-world library. Basically, i'm wondering if anyone has written an Inspector library for scala along the lines of what one found in Smalltalk.
Best wishes,
--greg
trait Inspector {
def showMethods( obj : Object ) : Array[java.lang.reflect.Method] = {
for (m <- obj.getClass.getMethods) yield { println(m.getName); m }
}
def showFields( obj : Object ) : Array[java.lang.reflect.Field] = {
for (m <- obj.getClass.getFields) yield { println(m.getName); m }
}
def showDeclaredFields( obj : Object ) : Array[java.lang.reflect.Field] = {
for (m <- obj.getClass.getDeclaredFields) yield { println(m.getName); m }
}
def showSuperclass( obj : Object ) : java.lang.Class[_] = {
val sup = obj.getClass.getSuperclass;
println( sup );
sup
}
def showInterfaces( obj : Object ) : Array[java.lang.Class[_]] = {
val sup = obj.getClass.getInterfaces;
println( sup );
sup
}
def showGenericSuperclass( obj : Object ) : java.lang.reflect.Type = {
val sup = obj.getClass.getGenericSuperclass;
println( sup );
sup
}
def showGenericInterfaces( obj : Object ) : Array[java.lang.reflect.Type] = {
val sup = obj.getClass.getGenericInterfaces;
println( sup );
sup
}
}
object Cluseaux extends Inspector {
}
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105
+1 206.650.3740
http://biosimilarity.blogspot.com
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105
+1 206.650.3740
http://biosimilarity.blogspot.com
Wed, 2009-03-04, 23:57
#2
Re: inspection library?
On Wed, Mar 04, 2009 at 02:13:18PM -0800, Meredith Gregory wrote:
> Below is a bunch of silly code the purpose of which is to identify the
> character of a real-world library. Basically, i'm wondering if anyone
> has written an Inspector library for scala along the lines of what one
> found in Smalltalk.
It's not as done as I'd like, but:
http://github.com/paulp/scala-improving/tree/master
In particular,
http://github.com/paulp/scala-improving/blob/208a5734fedff7a87f96c4e8a6a...
Thu, 2009-03-05, 00:07
#3
Re: inspection library?
On Wed, Mar 04, 2009 at 02:13:18PM -0800, Meredith Gregory wrote:
> Below is a bunch of silly code the purpose of which is to identify the
> character of a real-world library. Basically, i'm wondering if anyone has
> written an Inspector library for scala along the lines of what one found in
> Smalltalk.
I'm not sure if this is what you're after, but I've dabbled a little
with a Scala-ish reflection interface:
http://www.cs.helsinki.fi/u/lealanko/scala08/
I've been intending (for _years_ now!) to turn it into a real package,
but alas, there's always been something more urgent... If there's more
interest in this sort of thing, then please let me know, maybe I will
finally get the incentive to work on it.
Lauri
Thu, 2009-03-05, 00:27
#4
Re: inspection library?
Lauri,
Way cool. You might be interested in the approach i took to reflection in a concurrency setting. It eliminates many of the complications of higher-order concurrency calculi. It also addresses an alternative to the Pitts-Gabbay et al approach for the account of fresh name generation
Best wishes,
--greg
On Wed, Mar 4, 2009 at 2:59 PM, Lauri Alanko <la@iki.fi> wrote:
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105
+1 206.650.3740
http://biosimilarity.blogspot.com
Way cool. You might be interested in the approach i took to reflection in a concurrency setting. It eliminates many of the complications of higher-order concurrency calculi. It also addresses an alternative to the Pitts-Gabbay et al approach for the account of fresh name generation
Best wishes,
--greg
On Wed, Mar 4, 2009 at 2:59 PM, Lauri Alanko <la@iki.fi> wrote:
On Wed, Mar 04, 2009 at 02:13:18PM -0800, Meredith Gregory wrote:
> Below is a bunch of silly code the purpose of which is to identify the
> character of a real-world library. Basically, i'm wondering if anyone has
> written an Inspector library for scala along the lines of what one found in
> Smalltalk.
I'm not sure if this is what you're after, but I've dabbled a little
with a Scala-ish reflection interface:
http://www.cs.helsinki.fi/u/lealanko/scala08/
I've been intending (for _years_ now!) to turn it into a real package,
but alas, there's always been something more urgent... If there's more
interest in this sort of thing, then please let me know, maybe I will
finally get the incentive to work on it.
Lauri
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105
+1 206.650.3740
http://biosimilarity.blogspot.com
Sun, 2009-03-15, 13:47
#5
Re: Re: inspection library?
2009/3/5 Meredith Gregory :
> P.S. i find myself typing exprs like these (for (m <-
> obj.getClass.getMethods) yield { println(m.getName); m }) at the console all
> the time to go wondering through code the documentation of which i either
> know not where it lives or do not trust to be accurate or complete or
> authoritative.
I occasionally do the same thing. I like the following. It prints the
(Java) type signature.
obj.getClass.getMethods foreach println
Sun, 2009-03-15, 14:37
#6
Re: Re: inspection library?
On Sun, Mar 15, 2009 at 08:50:47PM +1000, Steven Shaw wrote:
> I occasionally do the same thing. I like the following. It prints the
> (Java) type signature.
>
> obj.getClass.getMethods foreach println
That's a built-in in my interpreter at home. This and many more handy
features coming soon to a trunk near you.
scala> val x = "abc"
x: java.lang.String = abc
scala> :inspect x
public int java.lang.String.hashCode()
public volatile int java.lang.String.compareTo(java.lang.Object)
public int java.lang.String.compareTo(java.lang.String)
public boolean java.lang.String.equals(java.lang.Object)
[...]
Or, already in trunk is completion:
$ scala -Ycompletion
scala> val x = "abc"
x: java.lang.String = abc
scala> x.
String = compareTo
length charAt toString
indexOf codePointAt codePointBefore
codePointCount offsetByCodePoints getChars
[...]
Below is a bunch of silly code the purpose of which is to identify the character of a real-world library. Basically, i'm wondering if anyone has written an Inspector library for scala along the lines of what one found in Smalltalk.
Best wishes,
--greg
trait Inspector {
def showMethods( obj : Object ) : Array[java.lang.reflect.Method] = {
for (m <- obj.getClass.getMethods) yield { println(m.getName); m }
}
def showFields( obj : Object ) : Array[java.lang.reflect.Field] = {
for (m <- obj.getClass.getFields) yield { println(m.getName); m }
}
def showDeclaredFields( obj : Object ) : Array[java.lang.reflect.Field] = {
for (m <- obj.getClass.getDeclaredFields) yield { println(m.getName); m }
}
def showSuperclass( obj : Object ) : java.lang.Class[_] = {
val sup = obj.getClass.getSuperclass;
println( sup );
sup
}
def showInterfaces( obj : Object ) : Array[java.lang.Class[_]] = {
val sup = obj.getClass.getInterfaces;
println( sup );
sup
}
def showGenericSuperclass( obj : Object ) : java.lang.reflect.Type = {
val sup = obj.getClass.getGenericSuperclass;
println( sup );
sup
}
def showGenericInterfaces( obj : Object ) : Array[java.lang.reflect.Type] = {
val sup = obj.getClass.getGenericInterfaces;
println( sup );
sup
}
}
object Cluseaux extends Inspector {
}
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105
+1 206.650.3740
http://biosimilarity.blogspot.com