3 ms·
I don't think I can read Io that well, but this doesn't seem like a very unique trick; Ruby has method_missing (like the first commenter mentions) and Python ha
by mapleoin 16y ago
I don't think I can read Io that well, but this doesn't seem like a very unique trick; Ruby has method_missing (like the first commenter mentions) and Python has __getattr__. Is there something else I'm not seeing in there?
- draegtun 16y agoAnd Perl has AUTOLOAD. However the difference to these is that Io is being lazy in the examples provided in the blog post. NB. its all just messages and no commas (ie. no args). ref: "Lazy Bricks, Lazy Mortar" by why - WayBackMachine link: http://web.archive.org/web/20080430135919/http://hackety.org/2008/01/10/lazyBricksLazyMortar.html http://web.archive.org/web/20080430135919/http://hackety.org...
- draegtun 16y agoBTW here is a quick & dirty example of Io laziness and shows what can be done without forward (did-not-understand/method_missing/__getattr__/AUTOLOAD): Hash := Object clone do ( with := method ( hash := Map clone call message arguments foreach (arg, # arg = k(v) for eg. t(0) k := arg name v := arg argAt(0) asString hash atPut (k, doString (v)) ) hash ) ) h := Hash with (t(0), f(1+1), with("hello"), writeln("not writeln!")) h2 := Hash with (t(100), f("hello" asUppercase), at("my at"), atPut("my atPut")) Above lazily goes through the Hash with() building the key/value pairs without ever running methods/functions with, writeln, at, atPut and simply takes the method/func name and evaluates its argument into a key/value pair: h at ("writeln") println # => "not writeln!" h at ("f") println # => 2 h2 at ("f") println # => "HELLO" This is the reflection alternative the author is referring to in his post.