On Dec 7, 2007 7:06 PM, Charles Oliver Nutter <[EMAIL PROTECTED]> wrote:
>
> John Wilson wrote:
> > Note *none* of the above require the dynamic language to support
> > optional static typing so I think it's an issue for Jython and JRuby
> > too.
>
> It's not nearly as much of an issue as you think. I tend to see
> categories of types here: integral types and composite types. When
> calling dynamic typed methods, obviously type is not examined unless by
> the actual method being called. When calling static-typed methods, JRuby
> only has implicit coercions for integral types like strings and numbers.

Quite so - the issue is how does the runtime know it's calling a
dynamically typed method when the only information it has is the
result of introspection on a CLass object?

> Composite types either need to actually be the type required by the
> target method (it must implement Map if it's to be passed to a Map
> method) or you must convert them into a type acceptable to the method
> you want to call. In no cases do we attempt to automatically coerce such
> types since that introduces an unacceptable object construction,
> conversion, and identity concern into method invocation.
>
> We don't try to pretend we're calling a dynamic language when we call
> Java...we fail fast if we can't do an integral type coercion.


I'm not sure I have explained the problem clearly enough (and note
that I don't think it's a big problem I introduced it as a "wrinkle"
in the initial post).

Let me try again:

Assume I have an dynamic language which can subclass Java classes and
call methods on classes in class files. This language's runtime system
used refection to find and make method calls. The runtime is asked to
dispatch "a.foo(1)" The variable "a" is an instance of class A and A
is available in a class file. When the runtime introspects the class
it finds that A has a method Object foo(object) and a superclass of A
has a method int foo(int). Which method should it call?

In my view it depends on the language in which A is written. If A is
written in Java then you call int foo(int). If A is written in the
dynamic language then you call Object foo(object).

If A is written in Java then you have to use the Java dispatch rules
(or, at least, as close as you can get) because that's the contract
you have with the class.

If A is written in the dynalang then Object foo(Object) is a method
which is designed to accept all types of parameter and should always
be called (We agree on this I think).

In order to implement this the runtime must know the language in which
A is written. In the case of JRuby/Jython this could be done with an
annotation on the class. In languages like Groovy/Ng which support
optional static typing you have to annotate the parameter and the
result type to distinguish between Object foo(object i) and def
foo(i).

In languages which support optional static typing there are even more
edge cases which require you to to distinguish between fields declared
as Object and ones which are untyped. I don't think these cases are of
general interest to this list!

John Wilson

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to jvm-languages@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to