Created
September 8, 2011 06:31
-
-
Save passingloop/1202777 to your computer and use it in GitHub Desktop.
7つの言語7つの世界 第3章 Io 言語のセルフスタディやってみた 2-3日目
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
book({"Author" : "Tate"}, | |
ul( | |
li("Io"), | |
li("Lua"), | |
li("JavaScript") | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OperatorTable addAssignOperator(":", "setPair") | |
Map setPair := method(k, v, | |
self atPut(k asMutable removePrefix("\"") removeSuffix("\""), v) | |
) | |
Builder := Object clone do( | |
output := Sequence clone | |
forward := method( | |
output appendSeq("<", call message name, ">\n") | |
call message arguments foreach(arg, | |
content := self doMessage(arg); | |
if(content type == "Map", | |
content foreach(k, v, | |
output removeSeq(">\n") appendSeq(" \"", k, "\"=\"", v, "\">\n") | |
) | |
) | |
) | |
if(content type == "Sequence", output appendSeq(content, "\n")) | |
output appendSeq("</", call message name, ">\n") | |
self | |
) | |
curlyBrackets := method( | |
self r := Map clone | |
call message arguments foreach(arg, | |
r doMessage(arg) | |
) | |
r | |
) | |
) | |
Builder doFile("book.txt") output println |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Builder := Object clone do( | |
forward := method( | |
indent | |
writeln("<", call message name, ">") | |
call message arguments foreach(arg, | |
depth = depth + 1 | |
content := self clone doMessage(arg); | |
if(content type == "Sequence", indent; writeln(content)) | |
depth = depth - 1 | |
) | |
indent | |
writeln("</", call message name, ">") | |
) | |
indent := method(depth repeat(write(" "))) | |
depth := 0 | |
) | |
Builder ul( | |
li("Io"), | |
li("Lua"), | |
li("JavaScript")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
squareBrackets := method( | |
call message arguments | |
) | |
l := ["foo", "bar", "baz"] | |
l type println | |
l asString println |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Matrix := Object clone do( | |
dim := method(x, y, | |
self cols := List clone setSize(x) | |
for(i, 0, x - 1, cols atPut(i, List clone setSize(y))) | |
) | |
set := method(x, y, v, | |
cols at(x) atPut(y, v) | |
) | |
get := method(x, y, | |
cols at(x) at(y) | |
) | |
load := method(path, | |
Lobby doFile(path) | |
) | |
save := method(path, | |
f := File with(path) | |
f openForUpdating | |
f write(self serialized) | |
f close | |
) | |
) | |
m := Matrix clone | |
m dim(3, 2) | |
m set(0, 1, "foo") | |
m set(2, 0, "bar") | |
m save("m.io") | |
n := Matrix load("m.io") | |
n get(0, 1) println | |
n get(2, 0) println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
くわしくは http://d.hatena.ne.jp/passingloop/20110909/seven_languages_in_seven_weeks_chapter_3_io_language_self_study