I have been living this last week in a pleasant fiction: I live in a world populated by regular updates, intelligent conversation, educated topics, and unlimited ice-cream. This pleasant fiction sustained me for a whole day, then I blew the rest of the week in learning a new programming language and researching what makes good language design vs bad language design, pros and cons of programming languages, and compilers for making my own language. You may be saying "Boring!", and in truth I often wonder why I find it so fascinating, but I still keep going back to the internet night after night trying to compile, learn, and educate myself about a language that will probably have no real application in ANY job I have, but leaning an entirely new language is quite informative.
In fact, for the last month, I've been growing frustrated with the rigidity of C++ and was looking for something similar to Squeak without the big footprint. The only languages I had heard about that might be able to help were dolphin (smalltalk variant) and Self. Neither of which are currently freely available for the windows system. My conclusion: develop my own programming language. I've had been making quite good progress until I ran across the IO programming language, and everything I was planning had been implemented and then some!
Warning: The following post will be technical and boring to those un-initiated into the world of computer programming. I also don't hold out much hope if this being interesting to those who are interested in programming.
IO Language: How is it different from C++ and Java? Let's do a quick comparison. C++ and Java are class based languages using function calls as the main process of execution. The IO language is completely different. The closest similarity I've seen is the language Self. (Javascript is also a similar language, but I don't know enough about it to vouch for that). IO is a prototypical, message based language. Everything is an object, and a message is required to do anything. There are no function calls - which makes for a very powerful threading pardigm. Hello world is an example of the language; just keep in mind that this is an interpreted language that a virtual machine translates (like Java).
"Hello World!" println
prints: Hello World!
Wasn't that cool? Let's try a larger, more typical example using obvious procreate a generic object we can use. the clone message create an exact copy
Hat := Object clone // create a "Hat" object
Hat size := 8 // size & 8 are Number classes
Hat refit := method( newSize, // we create a function here
Hat size = 9
)
"Hat size started out at " print
Hat size println
"Hat size after refit is " print
Hat refit
Hat size println
The output:
Hat size started out at 8
Hat size after refit is 9
Remember - even though the code looks like it uses function calls it doesn't. Let's take a look at the last line: Hat size println. Hat is an Object. size is a message sent to Hat which has a result of evaluating the code in the "size" slot which has a final value of the Number object 9. println is a message sent to Number which prints a number on the screen. You may say, "What does it matter? function calls and methods end up do the same thing." Ha. You've never worked with threads in MFC then. :-)
I would have given up on this language except for two breakthroughs. My first breakthrough came around hour six in trying to get IO to do things beyond simple assignments and methods: I managed to get the addons (like OpenGL) working! 3 hours later, I was ready to give up. I really, really, really wanted to be able to do a simple console application. And I found it. I'll post the answer below, but first I just have to explain my genius ( random luck) in figuring it out. I'm looking at the online reference for IO, and I see a core prototype called CLI. It was undocumented and I didn't have the source in the download I had, but no worries! The IO language provides self inspections. I can print ANY io code used/declared in the current object. I'm looking through the various functions and I see about 5 lines of code that composes the main loop to the entire program. Turns out that CLI is the main window! I quickly copied the CLI code and made my own, simple, easy, short console application template that does not depend on any addons! The cumulative effort of 9 solid hours of research and grunt work:
//Do the prototype creation and setup here
stdout := File clone standardOutput
stdin := File clone standardInput
while(true,
write("Your next wish? ")
line := stdin readLine
if(stdin isAtEnd, writeln; Lobby exit)
// Do actions here depending on user's typing
)
My next goal: implement Legends11. Legends11 is an unpublished game that my brother got for me about 10 years ago. It was text based, short (under 4 hours), simple, and fun. I've played it though 5-10 times and I still enjoy playing it.
Hint: doFile("filename.io") is a lifesaver if you decide to try out IO
2 comments:
There are a few things I'm not sure about IO.
Hat refit := method( newSize,
Hat size = 9
)
What is that "newSize," piece of text doing? To me it seems extraneous. Shouldn't the code be more like:
Hat refit := method(
Hat size = 9
)
I'm also wondering about the lines
stdout := File clone standardOutput
stdin := File clone standardInput
IO treats input and output like a file?
About the ":= Object clone" or ":= File clone" bits, what is the significance of "clone"? Why not just have
Hat := Object
Obviously I haven't done any research on IO, because otherwise I would probably find the answers, but I don't think I'm going to have much chance to work with IO.
What happened to Ruby? Too big of a footprint with its virtual machine? Is the IO VM truly much smaller?
The programming sample does have extra code. As you pointed out, the "newSize" variable is extra. If I wanted to use it, I should have said
Hat refit := method( newSize,
Hat size = newSize
)
To execute the refit line, I say
Hat refit(6)
The standardOutput feature is one I just figured out. I didn't even look in the "File" list because I wasn't expecting that feature there. That does require more research.
the clone message is my favorite feature. One way IO is different than Ruby is IO has no abstracts. Everything in IO is an instantiated object. If you want a new object, you copy an existing one.
Ruby was and is high on my list to learn. It's just simple preference. I really enjoy Smalltalk's (lack of) keywords and whenever I look at Ruby's 40 keywords, I move on for something a bit more towards what I enjoy. IO has no keywords.
I don't know how big a footprint Ruby has - likely small also. IO's virtual machine is a 25k executable. Squeak and Dolphin are full environments and are over 10 megs each - way to large for a simple single purpose application.
Post a Comment