Skip to content

Instantly share code, notes, and snippets.

@sriki77 sriki77/attrxml.io
Created Dec 4, 2011

Embed
What would you like to do?
Io Day 3
#!/usr/bin/env io
OperatorTable addAssignOperator(":", "genAttribute")
Builder := Object clone
Builder genAttribute := method(k,v,
k = k asMutable removePrefix("\"") removeSuffix("\"")
write(" "..(k)..("=\"")..(v).."\"") )
Builder curlyBrackets := method(
call message arguments foreach(v,doString(v asString));self)
Builder forward := method(
write("<",call message name)
args := call message arguments
if(args at(0) asString beginsWithSeq("curlyBrackets"), self doMessage(args removeFirst))
writeln(">")
args foreach(
arg,
content := self doMessage(arg);
if(content type == "Sequence",writeln(content))
)
writeln("</",call message name,">")
)
Builder ul(
li({"author": "Tate","style":"bold"},"Io"),
li({"x":"y"},"lua"),
li("JavaScript")
)
#!/usr/bin/env io
squareBrackets := method(
l := List clone
call message arguments foreach(v,l append(doMessage(v)))
l
)
[1,2,3,4] println
[1,2,["a","b","c"],3,4] println
#!/usr/bin/env io
Builder := Object clone
Builder indent := -1
Builder indentOutput := method(
for(i,1,indent, " " print)
)
Builder writeln := method(indentOutput;resend)
Builder forward := method(
indent = indent+1
self writeln("<",call message name,">")
call message arguments foreach(
arg,
content := self doMessage(arg);
if(content type == "Sequence",self writeln(content))
)
self writeln("</",call message name,">")
indent = indent-1
)
Builder ul(
li("Io"),
li("lua"),
li("JavaScript"),
ul( li(Ruby("First of the seven languages"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.