3 ms·
Sort of tooting my own horn here, but here's an HTML builder in the language I'm working on: http://gist.github.com/513228 http://gist.github.com/513228 (Exampl
by vito 16y ago
Sort of tooting my own horn here, but here's an HTML builder in the language I'm working on: http://gist.github.com/513228 http://gist.github.com/513228 (Example usage and output at the bottom.) I write these a lot to test a language's flexibility.
Seems like Io's "forward" is a lot like "did-not-understand" (and similar mechanisms in Ruby/etc. languages), but it takes priority over messages that would've otherwise been understood.
- draegtun 16y agoThats OK, toot away! But I'll toot my own as well then :) http://github.com/draegtun/builder http://github.com/draegtun/builder Mine (in perl) is more akin to Ruby's Builder by Jim Weirich (http://builder.rubyforge.org/ http://builder.rubyforge.org/) than out and out HTML builder. BTW, other HTML builders have been mentioned on HN before: http://news.ycombinator.com/item?id=1518096 http://news.ycombinator.com/item?id=1518096
- vito 16y agoNeat! They're pretty fun to make; I write them a lot to test a language's flexibility.
- draegtun 16y agoSeems like Io's "forward" is a lot like "did-not-understand" (and similar mechanisms in Ruby/etc. languages), but it takes priority over messages that would've otherwise been understood. Yes its same as did-not-understand/method_missing/__getattr__/AUTOLOAD but no it doesn't take priority over other defined messages. For eg, If I change the first line in my code above to: Builder := Object do ( foo := method (arg, write (arg)) ) And do: Builder do ( h1 ( foo ("Foo here!") p ("paragraph") ) ) I get a untagged "Foo Here!": <h1>Foo here!<p>paragraph</p></h1>
- vito 16y agoAh, ok - I misinterpreted the article. Actually, the article seems to be wrong? It seems to imply that this shouldn't work: Io> x := Object clone do( forward := 0; a := 1 ) ==> Object_0x1003a2e90: a = 1 forward = 0 Io> x a ==> 1 Io> x b ==> 0 Io> x b := 2 ==> 2 Io> x b ==> 2 (paragraph: There are some things you should know about forward(). It's very powerful. Too powerful. [...])
- draegtun 16y agoNot sure what the article is referring to there? As far as I know you would have to amend the objects protos or overwrite the setSlot message (which := is an alias for) to change this behaviour. The documentation clearly states for forward that: If an object doesn't respond to a message, it will invoke its "forward" method if it has one.