a koan (and a bug request)
Quiz: what will happen when the following code is run[*]? ================= class Trait { fun void announce() { <<< "I am generic." >>>; } fun void invoke() { announce(); } } class Legacy extends Trait { fun void announce() { <<< "I am legacy." >>>; } } class Lunacy extends Trait { public void announce() { <<< "I am lunacy." >>>; } } (new Legacy).invoke(); (new Lunacy).invoke(); ================= If you predict that it prints: "I am legacy." : (string) "I am lunacy." : (string) then here's a hint: there's a typo in the definition of Lunacy's announce() method where it says "public void announce()..." instead of "fun void announce()...". If you predict that it gets a compiler error when it encounters the typo, well, you'd be wrong there as well. What happens instead is that it compiles without any error messages, and the result is: "I am legacy." : (string) "I am generic." : (string) It took me a LONG time to find this one (and an even longer time to boil it down to a succinct example). Will the powers that be please take this as a request to beef up the parser? Thanks. - Rob [*] in particular, chuck v 1.2.1.3 mac os x : intel. I'm guessing that this is platform independent, though...
On 25 Jan 2010, at 06:56, Robert Poor wrote:
class Lunacy extends Trait { public void announce() { <<< "I am lunacy." >>>; } } (new Legacy).invoke(); (new Lunacy).invoke();
...
It took me a LONG time to find this one (and an even longer time to boil it down to a succinct example). Will the powers that be please take this as a request to beef up the parser?
The manual says that the P3-words (public, protected, private) are available, but not yet fully implemented. But it is a good question as to why one can drop "fun" here. It falls into the category of computer language quirks, or "gotchas" as they are called here: http://en.wikipedia.org/wiki/Gotcha_(programming) It is a difficult topic. It's like older airplanes often had the flaps up and gears up controls side by side. When landing a plane one must look outside, and not at those controls. So every once in a while, a pilot would make a gears up instead of flaps up when on the ground, resulting in the need for an expensive repair. So modern airplanes usually don't have them side-by-side. Hans
Hi all,
I believe that the "public void announce" declaration should work if
it's the only instance of that function. I was declaring functions
like this a few years ago when I first started chuck (thinking that I
could make public and private functions).
Rogan
On Mon, Jan 25, 2010 at 3:03 AM, Hans Aberg
On 25 Jan 2010, at 06:56, Robert Poor wrote:
class Lunacy extends Trait { public void announce() { <<< "I am lunacy." >>>; } } (new Legacy).invoke(); (new Lunacy).invoke();
...
It took me a LONG time to find this one (and an even longer time to boil it down to a succinct example). Will the powers that be please take this as a request to beef up the parser?
The manual says that the P3-words (public, protected, private) are available, but not yet fully implemented.
But it is a good question as to why one can drop "fun" here.
It falls into the category of computer language quirks, or "gotchas" as they are called here: http://en.wikipedia.org/wiki/Gotcha_(programming)
It is a difficult topic. It's like older airplanes often had the flaps up and gears up controls side by side. When landing a plane one must look outside, and not at those controls. So every once in a while, a pilot would make a gears up instead of flaps up when on the ground, resulting in the need for an expensive repair. So modern airplanes usually don't have them side-by-side.
Hans
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
Hans Aberg
-
Robert Poor
-
Rogan Carr