Skip to content

Instantly share code, notes, and snippets.

@sriki77
Created December 4, 2011 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sriki77/1429386 to your computer and use it in GitHub Desktop.
Save sriki77/1429386 to your computer and use it in GitHub Desktop.
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