archives

Introduction to E4X

Jon Udell posts a nice intro to E4X (running on Rhino).

A series of code snippets gives you a taste of how E4X can be used to manipulate XML.

Using continuations for web programming

The Cocoon project has introduced FlowScript. Flowscript is a
modified
version of javascript which supports continuations and is used to write web applications that span pages.



Here is an example from the site of a calculator application which uses multiple pages to request the numbers and
operator.



"In this example, the calculator function is called to start the calculator application. We'd like the sendPageAndWait function to be a special function, that takes as arguments an HTML file to be sent as response, and some optional data that needs to be placed dynamically in it. We would like sendPageAndWait to send the response page and then block the executing thread, until the user clicks on a link in the response page, which sends a request back to the server. This request resumes the processing at the point it was left, right after the call to sendPageAndWait."


function calculator()
{
  var a, b, operator;

  cocoon.sendPageAndWait("getA.html");
  a = cocoon.request.get("a");

  cocoon.sendPageAndWait("getB.html");
  b = cocoon.request.get("b");

  cocoon.sendPageAndWait("getOperator.html");
  operator = cocoon.request.get("op");

  try {
    if (operator == "plus")
      cocoon.sendPage("result.html", {result: a + b});
    else if (operator == "minus")
      cocoon.sendPage("result.html", {result: a - b});
    else if (operator == "multiply")
      cocoon.sendPage("result.html", {result: a * b});
    else if (operator == "divide")
      cocoon.sendPage("result.html", {result: a / b});
    else
      cocoon.sendPage("invalidOperator.html", {operator: operator});
  }
  catch (exception) {
    cocoon.sendPage("error.html", {message: "Operation failed: " + exception.toString()});
  }
}


Galois: high assurance software

The ICFP 2004 program now links to the invited talks, in particular PowerPoint slides and MP3 audio for John Launchbury's excellent talk on bringing functional programming to the real world at Galois Connections.