Le 25/03/2010 03:17, Charles Oliver Nutter a écrit : > I love Duby sometimes, I really do. > > I've just landed full dynamic dispatch support. Here's an example > script and session: > > ~/projects/duby ➔ cat examples/dynamic.duby > # Example of using a dynamic type in a method definition > def foo(a:dynamic) > puts "I got a #{a.getClass.getName} of size #{a.size}" > end > > class SizeThing > def initialize(size:int) > @size = size > end > > def size > @size > end > end > > foo([1,2,3]) > foo(SizeThing.new(12)) > > ~/projects/duby ➔ bin/duby examples/dynamic.duby > I got a java.util.Collections$UnmodifiableRandomAccessList of size 3 > I got a examples.SizeThing of size 12 > > I like this example because it's two totally disjoint types that > happen to both have a "size" method, and Duby + indy + dynalang > handles them just fine. > > So far I'm doing it like C#, specifying a "dynamic" type that > propagates as-is through the type inference phase(s), but for bytecode > and signature generation it gets erased to java.lang.Object. >
I've also found useful to propagate expected type back to the calling method. Example: if (foo()) { ... } should be translated to indy foo ()Z instead of ()Object because if () wait for a boolean. > - Charlie > Rémi _______________________________________________ mlvm-dev mailing list mlvm-dev@openjdk.java.net http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev