[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: From dynamic to static
- From: Chris Marrin <chris@...>
- Date: Mon, 31 Oct 2005 10:24:05 -0800
David Given wrote:
But the really cunning bit is that this applies to objects too. I can't
remember the syntax, so I'll switch to Lua-esque pseudocode. This:
...tells the compiler that o must be an object that implements method1. This
means that you can pass in *any object* that happens to implement method1 ---
it'll work, and be statically typed. Using his example, you could implement
Cat, Dog and Bob has three seperate classes, and provided they all
implemented the 'speak()' method, this function:
But this cannot be known at compile time in Lua (or any other
dynamically typed language that I know of). At compile time o may not
have a method1 function. But it hopefully will by the time it gets called.
chris marrin ,""$,
email@example.com b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'