Skip to content

Instantly share code, notes, and snippets.

@japaz
Created October 12, 2011 07:34
Show Gist options
  • Save japaz/1280539 to your computer and use it in GitHub Desktop.
Save japaz/1280539 to your computer and use it in GitHub Desktop.
7L7W Io - Day 3
Builder := Object clone
Builder addIndent := method(
for(i, 1, indent*2, " " print)
)
Builder indent := 0
Builder forward := method(
self addIndent
writeln("<", call message name, ">")
indent = indent +1
call message arguments foreach(
arg,
content := self doMessage(arg);
if(content type == "Sequence", self addIndent; writeln(content)))
indent = indent -1
self addIndent
writeln("</", call message name, ">"))
Builder ul(
li("Io"),
li("Lua"),
li(ul(
li("Java"),
li("C++"))),
li("JavaScript"))
OperatorTable addAssignOperator(":" , "atPutNumber" )
curlyBrackets := method(
r := Map clone
call message arguments foreach(arg,
r doMessage(arg)
)
r
)
Map atPutNumber := method(
self atPut(
call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\"" ),
call evalArgAt(1))
)
Builder := Object clone
Builder addIndent := method(
for(i, 1, indent*2, " " print)
)
Builder indent := 0
Builder forward := method(
addIndent
write("<", call message name)
firstMessage := call message arguments first
if( firstMessage != nil,
if(firstMessage name == "curlyBrackets",
attrs := doMessage(firstMessage)
if(attrs isKindOf(Map), attrs foreach(k,v,write(" ",k,"=","\"",v,"\"")))
)
)
writeln(">")
indent = indent +1
call message arguments foreach(
arg,
content := self doMessage(arg);
if(content type == "Sequence", addIndent; writeln(content)))
indent = indent -1
addIndent
writeln("</", call message name, ">"))
doString("Builder ul(
li(\"Io\"),
li(\"Lua\"),
li(ul(
li(\"Java\"),
li(\"C++\"))),
li(\"JavaScript\"),
book({\"author\": \"Tate\"}, \"Hi\"))")
// str := "Builder ul(li({\"class\":\"prototyped\"},\"Io\"), li(\"Lua\"), li(\"Javascript\") )"
// doString(str)
squareBrackets := method(
l := List clone
call message arguments foreach(arg,
l append(arg)
)
l
)
["1", "2", "3"] print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment