diff options
Diffstat (limited to 'io')
-rw-r--r-- | io/actors.io | 16 | ||||
-rw-r--r-- | io/builder.io | 15 | ||||
-rw-r--r-- | io/coroutine.io | 20 | ||||
-rw-r--r-- | io/phonebook.io | 28 | ||||
-rw-r--r-- | io/phonebook.txt | 4 |
5 files changed, 83 insertions, 0 deletions
diff --git a/io/actors.io b/io/actors.io new file mode 100644 index 0000000..9b63944 --- /dev/null +++ b/io/actors.io @@ -0,0 +1,16 @@ +slower := Object clone +faster := Object clone + +slower start := method(wait(2); writeln("slowly")) +faster start := method(wait(1); writeln("quickly")) + +slower @@start +faster @@start +wait(3) + + +futureResult := URL with("http://google.es") @fetch +writeln("Do something immediately while fetch goes in bg...") +writeln("This will block until the result is available.") + +writeln("Fetched ", futureResult size, " bytes") diff --git a/io/builder.io b/io/builder.io new file mode 100644 index 0000000..482c005 --- /dev/null +++ b/io/builder.io @@ -0,0 +1,15 @@ +Builder := Object clone +Builder forward := method( + writeln("<", call message name, ">") + call message arguments foreach(arg, + content := self doMessage(arg) + if (content type == "Sequence", writeln(content)) + ) + writeln("</", call message name, ">") +) + +Builder ul( + li("IO"), + li("Lua"), + li("Javascript") +) diff --git a/io/coroutine.io b/io/coroutine.io new file mode 100644 index 0000000..8c9d743 --- /dev/null +++ b/io/coroutine.io @@ -0,0 +1,20 @@ +vizzini := Object clone +vizzini talk := method( + "Fezzik, are there rocks ahead?" println + yield + "No more rhymes now, I mean it." println + yield +) + +fezzik := Object clone +fezzik rhyme := method( + yield + "If there are, we'll all be dead." println + yield + "Anybody want a peanut?" println +) + +vizzini @@talk +fezzik @@rhyme + +Coroutine currentCoroutine pause diff --git a/io/phonebook.io b/io/phonebook.io new file mode 100644 index 0000000..c073cf2 --- /dev/null +++ b/io/phonebook.io @@ -0,0 +1,28 @@ +OperatorTable addAssignOperator(":", "atPutNumber") + +curlyBrackets := method( + r := Map clone + call message arguments foreach(arg, + r doMessage(arg) + ) + r +) + +#Map atPutNumber := method(n,elm, +# self atPut( +# n asMutable removePrefix("\"") removeSuffix("\""), +# elm +# ) +#) + +Map atPutNumber := method( + self atPut( + call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""), + call evalArgAt(1) + ) +) + +s := File with("phonebook.txt") openForReading contents +phoneNumbers := doString(s) +phoneNumbers keys println +phoneNumbers values println diff --git a/io/phonebook.txt b/io/phonebook.txt new file mode 100644 index 0000000..c590976 --- /dev/null +++ b/io/phonebook.txt @@ -0,0 +1,4 @@ +{ + "Bob Smith": "5195551212", + "Mary Walsh": "4162223434" +} |