Inference rules in HTML

I hacked together a javascript function to make it easy to write inference rules in HTML. For example, to generate this:

    a→b     b→c
     HYP-SYL
    a→c

I just have to write this:

    rule("HYP-SYL", ["a→b", "b→c"], "a→c"])

Here's the function:

    function rule(name, top, bottom) {
        var top = top.join("     ");
        document.write(
            "<p><table cellpadding=0>" +
            "<tr>" +
                "<td align=center>\n" + top + "</td>" +
                "<td></td>" +
            "</tr>" +
            "<tr style='line-height:0.1'>" +
                "<td align=center'>" +
                    "<div style='border-bottom: solid 1px #000'></div>" +
                "</td>" +
                "<td> " +
                    // position:relative is necessary to prevent IE from
                    // clipping off the top and bottom of the name
                    "<span style='position:relative'><tt>"+name+"</tt></span>"+
                    "</td>" +
            "</tr>\n" +
            "<tr>" +
                "<td align=center>\n" + bottom + "</td>" +
                "<td></td>" +
            "</tr>" +
            "</table></p>"
        )
    }
    

I hope someone out there finds it useful.

Posted on January 1, 2006 05:44 PM
More languages articles

Comments

sweeeet.

now make one that can do arbitrary numbers of inference rules.

THEN make one that can take a context-senstive grammar and an expression written in that grammar and generate a type-inference tree!

Posted by: John Bachir at January 1, 2006 08:14 PM

Oh, nice!

This reminds me a bit of ASCIIMathML - have you had a chance to check that out at all? It's pretty rocking.

Glad to see that you're still around and posting, by the way. It's been ages! How are things in Boston?

Posted by: Gnomon at January 1, 2006 10:46 PM

Wow. AsciiMathML is quite spiffy, indeed. Thanks for the pointer.

For some reason I just haven't felt like posting much recently. Most of my spare time for the last couple months has been going into reading TAPL, or Zinn's "Declarations of Independence", or thinking about FrTime. You'd think that one of these would have led to a shareable thought, but apparently not.

I guess my tolerance for making a fool of myself has decreased :) For example, now that I think about it, I really should have made my javascript function generate mathml instead of a hacky html table. Oh well...

Posted by: Kim at January 2, 2006 12:28 AM
Post a comment









Remember info?




Prove you're human. Type "human":