Io: my errno adventure in C

This pastie holds my first C patch. It actually repaired a Readline problem that appeared on my Mac when I git pull‘d Io’s source today. See the Io issue at their bugtracker.

The pgsql heroes fixed the problem way before, so I could stand on the shoulders of smart giants.

I don’t know how to test C stuff, except for running the programs, and Jonas reminded to actually do that:

c-5b66e555:~ olle$ rm .io_history
c-5b66e555:~ olle$ mkdir .io_history
c-5b66e555:~ olle$ io
Io 20080120

 Exception: while loading history file '/Users/olle/.io_history', reason: Is a directory
 ---------
 loadHistory                         Z_CLI.io 47
 ReadLine ?                           Z_CLI.io 47
 Call relayStopStatus                 A2_Object.io 295
 CLI loadHistory                      Z_CLI.io 94
 CLI interactiveMultiline             Z_CLI.io 82
 CLI run                              IoState_runCLI() 1

c-5b66e555:~ olle$

So, the complaining functionality is retained.

What’s it do?

For those who are beginners at C, like I am, this small digression might interest:

  • First we include the errno mechanism as an include: #include <errno.h>
  • in each function, initialize the value of the static global variable “errno” to 0
  • functions like read_history(filename), from the libedit library return an int, but…
  • We are not interested in the return value, so we cast the computation to be void, the errno mechanism will take care of remembering that int on its own
  • It seems to be culturally correct to check for success instead of failure.

All these factoids are guesstimates of what went on, and I’m interested in the real story someday. Please provide any insight as comments, dear reader.

PS: As you can tell, mucking about other people’s C code is not something I do every day. I felt good, but weird.

WideFinder in Io: it’s now too late

A Swede made the first WideFinder implementation in Io: Ragnar Dahlén.

The results were informative, but not performant. Io can not compete just there, just yet.

Me and Thorbiörn were conspiring last week to implement WideFinder, but we got waylaid by… distractions. The distractions were speculative, lazy, and touched on different OCamls. Like this: “We need an OCaml-shaped project. To help us learn.”

The usual get-started project is “Make an HTTP server than can 200 and 404. At least.” Hardly qualifies as OCaml-shaped…

IoPython, raw but cool

I nosed around in Io’s “addons” folder, which you also can pull from the Git repository, see the Io homepage.

Update: of course, this was reported when it was fresh, with nice examples, too: pinupgeek’s blog is full of Io goodness. (Thanks, trevor!)

While nosing, I met the Python module, which lets you run Python functions in Io. It was written last year, the copyright statement shows:

  docCopyright("Aslak Gronflaten", 2006)

IoPython lacks tests, real documentation, and such, and it does not do memory management:

* Convert an Io object to PyObject.
* At the moment, we can't pass in any objects, just those that can be translated,
* until I build a python wrapper around an io object, reverse of what I did here.
* TODO: Memory management!!!

Does not seem impossible.

But I get a nice vibe from these lines:


  # Import a module
  sys := Python import("sys")

  "Which version of python are we running?" println
  sys version println

  "System path is returned as a list" println
  sys path foreach(p, p println)

  "Load the string module" println
  string := Python import("string")

  "Split a string" println
  str := "Brave brave Sir Robin"
  str println
  string split(str) println

  "Load a C module (.so)" println
  t := Python import("time")

  writeln("Current time is: ", t time)

  "Another way to invoke a method" println
  str = "UPPERlower"
  write(str, " --> ")
  string invoke("swapcase", str) println

Io could improve its library situation, if IoPython were less raw. Things will improve with time. In the meantime, I’m gonna learn more Io.