Skip to content

Instantly share code, notes, and snippets.

View hashmal's full-sized avatar

Jérémy Pinat hashmal

View GitHub Profile
@hashmal
hashmal / messageSerialization.io
Created March 1, 2014 23:22
Add message serialization support to Io (might be useful to pass messages to other processes or even over a network)
Message justSerialized := method(stream,
stream write(name)
if(arguments size > 0,
stream write("(")
stream write(arguments map(serialized) join(", "))
stream write(")")
)
if (next,
if (next isEndOfLine not, stream write(" "))
stream write(next serialized)
with IO
routine main() {
IO.stdout.write("Hello, world!\n".bytes())
}
# Class inheriting from this are be able to declare abstract methods that
# must be implemented by some other classes. Example:
#
# class A < Interface
# abstract :foo
# end
#
# class B
# implement A
# end
Once there was a young rat named Arthur, who could never make up his mind. Whenever his friends asked him if he would like to go out with them, he would only answer, "I don't know." He wouldn't say "yes" or "no" either. He would always shirk making a choice.
His aunt Helen said to him, "Now look here. No one is going to care for you if you carry on like this. You have no more mind than a blade of grass."
One rainy day, the rats heard a great noise in the loft. The pine rafters were all rotten, so that the barn was rather unsafe. At last the joists gave way and fell to the ground. The walls shook and all the rats' hair stood on end with fear and horror. "This won't do," said the captain. "I'll send out scouts to search for a new home."
Within five hours the ten scouts came back and said, "We found a stone house where there is room and board for us all. There is a kindly horse named Nelly, a cow, a calf, and a garden with an elm tree." The rats crawled out of their little houses and stood on the floor in
--------------------
-- SUDDENLY OOP!! --
--------------------
-- Let's simulate a class... But since it's Shirka, it has to be different.
-- Let's make an AGENT! It would just be a task spawner...
(agent => User) [ -- `agent` would wrap a list inside a `receive`, and
(=> html) [ :body unquote split snd-fst -> header -> body "<html>" puts
"<head>" puts header ([length? 0 >] while) [ uncons :title= unquote = (!?) [
"<title>" print uncons print "</title>" puts ] ] << "</head>" puts "<body>"
puts body ([length? 0 >] while) [ uncons -> w w :h1 unquote = (if) [ [ "<h1>"
print uncons print "</h1>" puts ] [ w type? :List = (if) [ [ "<p>" print w
print "</p>" puts << ] [ w :h2 unquote = (!?) [ "<h2>" print << uncons print
"</h2>" puts ] ] ] ] ] ] << "</body>" puts "</html>" puts ]
------------------------------------------------------------------------------
-- floating point arithmetic errors now in Shirka!
0 [ 0.0001 + ] 10000 times
puts --> 0.99999999999991
-- Copyright (c) 2013, Jeremy Pinat.
------------------------------------------------------------------------------
-- --
-- PARSER TESTS --
-- --
------------------------------------------------------------------------------
(with) "lib/test.shk"
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.ali
*.so
(with) "lib/atl.shk"
(test/runSuite) [
("true" test/case) [ -- this test always succeeds
(test/assertions) [
[ TRUE ]
]
]