The things we do

I started this afternoon wanting to get some hacking done on our Jukebox code, which is written using MzScheme’s web-server, but I’ve been pretty thoroughly distracted: first by the notion of using postgresql instead of flat-files for the Jukebox database, leading to my earlier scheme-pg post, and then by the desire to move the 8020 site over to darcs from tla, which led to exploring a chain of recursive dependencies. The arch2darcs program requires the missingh library, which in turn needs Cabal; so I decided the path of least resistance was upgrading to ghc 6.4.1, which seems to involve building from source when working on MacOS X. The build somehow caused make to spin endlessly (or at least it was giving no visible signs of progress), and I’ve given up on the whole line of investigation and am going back to the relative safety of working on the Jukebox itself.

So back to the Jukebox: over the last three weeks I’ve had an opportunity to teach myself basic JavaScript and AJAX techniques. Paul’s new Jukebox code uses nevow’s “livepage.py” features, which make a great substrate for a good Jukebox user-interface, with queue- and volume-updates broadcast to connected clients, and I’m thinking of adapting the existing Jukebox to do something similar using my new JavaScript skills.

scheme-pg port to MacOS X, MzScheme v299.400

I’ve just finished taking scheme-pg version 0.4.0, which is intended for MzScheme version 299.30, and updating it (1) so that it builds on MacOS X, thanks to Geoffrey Knauth’s patches (slightly edited to undo some kind of whitespace mangling probably introduced by the HTML mailing-list archiver); and (2) so that it builds with MzScheme v299.400. The only change to the Scheme code is in sql.ss — MzScheme v299.400 seems to have sprouted versions of string-upcase, string-titlecase, and string-downcase that conflict with SRFI-13’s versions of the same procedures.

My revised scheme-pg package is available at http://www.eighty-twenty.org/~tonyg/Darcs/scheme-pg/. That’s both a browseable snapshot, and a darcs repository that you can retrieve with

darcs get http://www.eighty-twenty.org/~tonyg/Darcs/scheme-pg/

Mac Powerbook 12" repaired, finally!

After an appallingly long delay (longer than two months!), during which I fretted about the difficulty of fixing my broken laptop (but also learned to ride a motorcycle in my vastly expanded free time), I finally caved in and found a local repair shop (warning: link will resize your window) who would take the case. They did a great job of soldering a new (ad-hoc) connector to the motherboard for me. The power button worked fine when the machine was returned to me.

Unfortunately, I’d broken the keyboard’s ribbon-connector when I’d been taking the thing to pieces and putting it back together again, and the repair outfit had done the best they could with the broken cable I’d left them. Only about a third of the keys were working, so I called up the repair shop and ordered a new keyboard, which arrived the next business day. After all my experience taking the damned thing to pieces, I now rate myself at such a basic job as PowerBook keyboard replacement, so I opted to do it myself, and after an embarrassing false start, having forgotten to remove the remnants of the old broken connector from the socket on the motherboard, the new keyboard is installed and working perfectly.

Um, we now return you to your regularly scheduled 8020.

Mac Powerbook 12" hard-disk surgery

On Sunday I replaced the hard disk in my powerbook, according to the instructions here. Everything went well up to

Pull them out very carefully, as there are very thin cables on the connectors.

It turns out that there are very thin cables on the connectors. Now, I had the good fortune not to break any of these thin cables. What I did end up doing was accidentally removing the entire power connector socket from the motherboard. This was far, far easier than it should have been:

  1. The solder holding the socket to the motherboard was bad, and the socket was very loose to begin with; and

  2. The plug inserted into the socket was jammed tight. No force on Earth was going to separate that plug from its socket. (After it was thoroughly removed from the mainboard, I figured there was no point in being delicate, so took a couple of pairs of pliers to it to try to get the plug and socket separated. No luck. It may as well be glued shut!)

In desperation I googled around trying to find something to avoid consigning the whole machine to the tip. I found this, a more professional (and slightly more accurate) version of the same hard-disk replacement instructions. Note particularly the warning on this page,

The cables you’re about to remove are very fragile - do not pull directly on the wires. Instead, try to pry up the connector directly, using your fingernails or a small flathead screwdriver if necessary.

Yeah, no kidding.

So, now I have a Powerbook, with a brand-new working disk, that I can’t switch on — at least not while the keyboard is connected. Shorting the traces on the motherboard with a screwdriver caused it to power up, boot correctly, and happily wait for a login from the non-connected keyboard, but I don’t really want to try my luck by turning it on and then reconnecting the keyboard while it’s running (and never switching it off again). Neither are my soldering skills good enough to attempt soldering a new connector onto the (very small) traces on the circuitboard. I guess my options are either find a soldering expert, or discover some way of switching the machine on without using the power button.

In hindsight, what I should have done (and this could be added as a hint to the two how-to pages I linked to above) is to cut the power wires to avoid having to pull out the plug in the first place. Once the hard-disk was replaced, it would have been a simple thing to solder the wires together again, or to add a simple in-line jumper to allow future removals of the top panel.

Partial Evaluation

This afternoon I implemented a simple partial evaluator for a Scheme-like language, based on the paper “Partial Evaluator as a Compiler for Reflective Languages” (Asai, Masuhara, Matsuoka and Yonezawa, 1995). So far I’ve restricted myself to an IO-free, side-effect free language, but by using the notion of preactions I ought to easily be able to add support for IO. I’d like to explore extending the simple system I have now to cope with the Composable Memory Transactions of Harris et al instead of supporting Scheme’s destructive updates.

The addition of pattern-matching data-destructuring will help the partial evaluator out, too, in the same way it makes dealing with primitive data easier for the Spineless Tagless G-Machine (see section 4.7). For example, using the partial evaluator to specialize the expression

(fold + 0 a)

I currently get

(letrec ((g17 (lambda (x acc)
                (if (null? x)
                  acc
                  (GOTO g17
                        (if (pair? x)
                          (PRIMcdr x)
                          (error '"Not a pair in cdr" x))
                        (+ (if (pair? x)
                             (PRIMcar x)
                             (error '"Not a pair in car" x))
                           acc))))))
  (g17 a '0))

(Ignore the strange GOTO syntax — I’m also experimenting with identifying the places I can transform recursive procedures into iterative loops.) Note that the type test (pair? x) is repeated twice. If some kind of match clause were used instead, we would see the test lifted to wrap the (GOTO g17 ...) expression, leaving us with something more like

(letrec ((g17 (lambda (x acc)
                (if (null? x)
                  acc
                  (if (pair? x)
                      (GOTO g17 (PRIMcdr x) (+ (PRIMcar x) acc))
                      (error '"Not a pair in match" x))))))
  (g17 a '0))

which, when compiled, is about as efficient as you will get with a statically compiled Scheme. Lots of the optimizations developed in the Self system apply to dynamically compiled variants, of course, potentially leading to further efficiencies.

Syntactic Closures vs. syntax-case

On this page about syntactic closures, we see the definition of an anaphoric-if macro that doesn’t transmit the “it” binding to the alternative clause — just to the consequent. This is pretty sophisticated. I immediately began to think about how you could do the same with syntax-case (as clearly others had before me) and it turns out to actually be easier. The only real downside is the introduction of another binding — but of course the mythical Sufficiently Smart Compiler will optimise that away immediately anyway.

Chicken Cairo 0.1.2 alpha

"Release early, release often," they say. In this spirit, another release of Chicken Scheme bindings for Cairo is available in our 2005 archive.

The egg file is available in releases.

2005-01-06 18:15:03 GMT Michael Bridgen <mikeb@lshift.net>      patch-8

    Summary:
      Added text and font extents
    Revision:
      chicken-cairo--dev--0.1--patch-8

    - cairo_text_extents_t and cairo_font_extents_t types
      These are not returned from a function, so we have to allocate
      them as a (GC-able) byte vector and make C think it's a spot of
      memory.
    - Functions for determining the extents of text and fonts.
    - Updated example



2004-12-04 17:52:21 GMT Tony Garnock-Jones <tonyg@lshift.net>   patch-7

    Summary:
      Adapt to chicken-sdl's recent case changes, and upcase the cairo binding too
    Revision:
      chicken-cairo--dev--0.1--patch-7

    A few constants changed to UPPER_CASE, both references to SDL
    constants, and the flags defined in cairo.scm. Also removed test-cairo
    from the Makefile - it doesn't need to be compiled now that we have
    sdl-csi.


2004-11-30 00:40:37 GMT Michael Bridgen <mikeb@squaremobius.net>        patch-6

    Summary:
      Font and text rendering
    Revision:
      chicken-cairo--dev--0.1--patch-6

    Just a start on these -- enough to see something painted, which is exciting.


2004-11-17 19:40:06 GMT Tony Garnock-Jones <tonyg@kcbbs.gen.nz> patch-5

    Summary:
      cairo.setup file, to make 'make install' (and the egg) work
    Revision:
      chicken-cairo--dev--0.1--patch-5



2004-11-15 22:33:03 GMT Michael Bridgen <mikeb@squaremobius.net>        patch-4

    Summary:
      Query functions
    Revision:
      chicken-cairo--dev--0.1--patch-4

    Might come in handy ('specially alpha)


2004-11-15 14:02:26 GMT Michael Bridgen <mikeb@squaremobius.net>        patch-3

    Summary:
      Matrix operations (untested)
    Revision:
      chicken-cairo--dev--0.1--patch-3

    Added the cairo_matrix_* functions -- untested, except for the
    compilation unit test.

    Just a bunch of typing really.


2004-11-11 00:19:12 GMT Michael Bridgen <mikeb@squaremobius.net>        patch-2

    Summary:
      Some documentation and decorations
    Revision:
      chicken-cairo--dev--0.1--patch-2

    Added some documentation regarding obscure/non-obvious things;
    divided into sets of functions with headers for navigation.

GNU/Arch archives moved

I’ve cycled our GNU/arch archives to 2005, meaning that the previous archive link is wrong. To correct:

tla register-archive http://www.eighty-twenty.org/archives/2004
tla register-archive http://www.eighty-twenty.org/archives/2005

A Web view for zowie

The aim of Fuschia was to write a clean, Python-based, blosxom-like blogging tool. As soon as I’d started though, I got grand plans and lost my way. Now I’ve turned back to it as a testing ground for some zowie ideas.

I branched Fuschia to try making a web site by projecting an RDF model along semantic relations. This is very zowie-ish, so I’m going to write about my experiments here.

The view

Here I ran into the dilemma of having either a single model, and constructing views using a projection and a subject (a subject-centric view); or having a graph of views and the models distributed among them (a state-centric view).

A zooming user interface may have a locus of attention (either explicitly as in an insertion point, or guessed from the input device state, like mouse position) but it may not always have an explicit subject aside from the world. Hence it’s difficult to have a subject view; however, you can on the other hand, let the state of the view decide this for you — rendering the view becomes:

  1. start at the top-level view, and find the top-level subject
  2. project the semantic relations (to the current subject) onto spatial relations
  3. for each related subject, make an appropriate view and go to 1.
  4. composite the responses according to the spatial relations

Naturally, the state of a view along with the spatial relations in the projection will mean that some related subjects are outside the clipping area, too small, &c., so these won’t be rendered.

A Web site always has an explicit subject, given by the URL. Our algorithm is very similar to the state-centric case:

  1. make the current subject the one requested
  2. project the semantic relations to the current subject onto Web page relations
  3. for each related subject, make an appropriate view and go to 1.
  4. compose the response HTML according to the Web page relations

It looks like a Web site (in this experiment) approximates the smoothly interactive interface with discrete, subject-sized steps. The state of the view is implicit in the explicit subject, rather than subjects being interpolated between by the view state.

The model

What do we want from the model? In the MVC sense, a model fulfils two roles: being a value cell, and being observable (letting the view know when the value changes). Since I don’t initially have a controller changing the model, I can not worry so much about being observable, and just hold a value. Primarily, I need to know semantic relations between subjects (resources) and objects (values). These are naturally expressed (because it suits my purpose) as a RDF triples database. My model for a particular subject is the set of relation-arcs leading outwards; for this we really only need a reference to the triples database, the subject itself, and a way to query the database.

I started by representing some facts about (say) a part of the filesystem. We have to know what form these facts are going to be for us to reason using them later, so I use a standard set of facts about containment and names of things. From this basic set of explicit relations and an inference procedure, I can infer other relations such as ancestry, transitive containment, and so on. We can also use these to project our filesystem facts into semantic relations (‘classified-as’), and our semantic relations into view-specific relations (‘linked-to’).

Style and templates

Assumed in the above algorithms is a procedure for determining the appropriate view for a subject. Here I have a number of options, including:

Have a statically configurable map of subject type to view. This is essentially a view factory, and conceptually straight-forward so far as it goes. It leaves the matter of templates alone — concievably some views would use some kind of templates, which leads to coupling between the template language and the view projection.

Use context and selector-matching to determine the view (or style) to use, in the manner of CSS or GSS stylesheets. This is really a refinement of the above; however, since we have context, we can stick to styles and simply have some styles that rule out rendering a subject. We don’t have to resort to control structures or even have templates.

Direct the view rendering through templates entirely, using selectors and control structures, in the manner of XSLT. Although this is a nice pun on XSLT, and could even be workable using XSLT, it is more or less what I’m trying to avoid. I want to extract the relations implied in such templates and keep them explicitly in one place — the projection.