Things I haven't figured out yet. :-)
How "safe" is it to add methods to core objects like Object, Sequence and Number? What are the odds that if I use someone's library, they have used the same name so a conflict occurs?
Ruby offers the same feature, and problems *do* occur. See, for example: http://kylecordes.com/2006/04/01/rmagick-pain/
A: As explained by jer: "Create a clone of Object, define your method on that object, then append that object to said Sequence's protos list. That way, if someone else defines a method on the same object with the same name, theirs will take precedence (or if they do the same trick as you, yours will take precedence)... either way, I personally consider the former bad style; you should append an object to the protos list."
Consider the following code:
Io> A := Object clone do( value := 42 ) ==> Object_0x743cb8: value = 42 Io> A + := method(y, self value + y) ==> method(y, self value +(y)) Io> A + 3 ==> 45 Io> A plus := method(y, self value + y) ==> method(y, self value +(y)) Io> A plus 3 Exception: argument 0 to method '+' must be a Number, not a 'Object' Coroutine_0x74c1f8 stack trace ------------------------------ + doString line 2 Object plus doString line 2 ==> nil Io> A plus(3) ==> 45
When I define a method + on A, I can call it like this: A + 3. However, when that same method is called plus, A plus 3 doesn't work; it has to be called as A plus(3). Why is that? Obviously + has some kind of special status, probably because it is an operator. Can this kind of status be set manually? How does it work?
A: jer: "[This] happens because the parser transforms a set of KNOWN operators to include the parens if they aren't present; so unless you add your "plus" method to that list (IoToken_parser.c <-- in there); then it will always need explicit parens."
SteveDekorte: "The only difference between + and plus is that operators are parsed differently. But if you use parens, they are the same: A +(3) == A plus(3)."
Does Io have getattr and setattr hooks like Python? If not, can they be implemented? Is it useful to do so?
A: jer: "We use setter methods for that. I.e. setFoo(42). You should avoid obj foo := x; mostly as a style thing."
How does forward work exactly? It doesn't work for all objects, apparently (Locals comes to mind). Does an object need to derive from Object in order for it to work? (Probably not...)
A: According to Steve Dekorte, it does work with Locals. I need to come up with an example...