I don't know if you're still arguing about this (skipped the last 15 posts), but:
Code:
print("This and that")
should be a free function, no method call on whatever, while
Code:
stdout.write("This and that")
is a method on an open file-like object replacing the standard output stream. But if we do this:
Code:
stdout.write = somefunc
stdout.write("This and that")
we assign stdout.write to somefunc, where it replaces the method itself. So stdout.write is a free function and not related with stdout itself (except in the case where somefunc is a method). That was my point.
My implementation approach: Every type has some related information (operators, methods, name) etc.accessible from ANY instance of that type. When you use dot notation, the interpreter first searches all the attributes in that specific instance. If it didn't found one, it finds a method. The method is wrapped with the implicit first argument and pushed onto a stack (or into a register). Then the method is called, and the call function passes also the saved first argument. Like:
Code:
stdout.write("This and that")
Parsed, tokenized etc. I assume a stack-based machine:
push stdout onto the stack - Easy
Find an attribute named write. If you found one, push it. Else, search in stdout's type's methods.
If you found one, wrap it with stdout as first argument and push a copy. Else, raise an error.
No explicit argument - Argc = 0
Call the top of stack with no argument.
Push the result
------ WHILE ------
write_to_file(stdout, "This and that")
Push write_to_file
Push an argument stdout (Argc = 1)
Another one ("This and that", Argc = 2)
Pop Argc items, and call the last function with those arguments.
Push the result.
While a method could be a struct of a function and first argument.
I think in C++ a compiler rewrites method definitions with a first argument (this) and calls to "Class::Method(instance, ...)". But this is better for intepreted languages, don't you think? And absolutely no changes in syntax. Only the normal dot for attribute access (or method, in this case).