Dylan compared to Python
Jason Trenouth
jason at harlequin.co.uk
Fri May 21 04:50:53 EDT 1999
On Thu, 20 May 1999 17:22:44 -0500, Paul Prescod <paul at prescod.net> wrote:
> Tim Peters wrote:
> >
> > so-many-electrons-so-little-time-ly y'rs - tim
>
> It seems like Dylan implements polymorphism by allowing a "generic
> function" to dispatch on multiple arguments. How does this work with
> separate compilation?
>
> In Python I can do this:
>
> def a( foo ):
> foo.a()
>
> and foo could take an infinite number of types. This code can be
> "compiled" (byte-compiled) without knowing what type foo will take at
> runtime. To implement this feature in statically typed languages usually
> requires pre-declared interfaces and/or subclassing. Is this the case with
> Dylan?
Dylan is a dynamically typed language. That's where the name comes from
"DYnamic LANguage". So I can easily write a function that takes any argument
of any type:
define function a (foo) ... end
and then call it on any object:
foo.a
A difference with Dylan is that implementations can optimize the code if you
put a bit more information in your programs:
define method a (foo :: <integer>) ... end
define method a (foo :: <string>) ... end
define method b (foo :: <integer>)
foo.a
...
Now the call to "a" inside method "b" can be dispatched more efficiently.
__Jason
More information about the Python-list
mailing list