The Avail Programming Language
Mobile Users: Click here to view our text rendering warning.

Wump the Wumpus

Apologies for the long hiatus between newsletters. Before the website went up, these were sent from a personal e-mail account to the small list of Avail insiders. But the website is now a more appropriate venue, so please look for newsletters here. There is no commitment to a particular frequency yet, but having said that, hopefully there will be a newsletter every week so that interested parties can stay current with Avail developments.

Wump it Good

This week, Wump the Wumpus, an Avail adaptation of Gregory Yob's 1972-3 text adventure classic, Hunt the Wumpus, was published to the source repository. The project-relative path to the codebase is examples/Wump the Wumpus. To actually play the game, build examples/Play Wump the Wumpus. While the game is meant to amuse for a few minutes or hours at most, the primary value resides in its source code. Wump the Wumpus is a pedagogic exercise in developing a nontrivial application in Avail.

Unfinished Business

The exception handling machinery now supports unwind protection. The method formerly named "Guard|guard_«intercept_»" is now "Guard|guard_«intercept_»«ensure_»". The first argument is the guarded function, the second argument is a tuple of exception handlers, and the (new) third argument is an optional unwind handler. Whether a guarded function runs to completion or is curtailed by an exception, the associated unwind handler always runs. This functionality is equivalent to the try/catch/finally control structure from Java or C#, the try/except/finally control structure from Python, or the begin/rescue/ensure control structure from Ruby. The unit test, new-avail/Avail/Foundation Tests/Exception Tests, is rife with examples that should demonstrate the nuances of exception handling.

If At First You Don't Succeed…

The standard library now supports computational backtracking. Backtracking is the technique of checkpointing the execution of an algorithm so that it is possible to abandon a path of computation and proceed along a different path that diverges at a checkpoint. To use backtracking, first establish a dynamic fence with "Backtracking fence_". The argument is a function within which backtracking primitives may occur. There are two classes of backtracking primitives: those which establish checkpoints and those which resume checkpoints. In the former class are "first try", which establishes a checkpoint and then answers true; "trial`#of_", which establishes a checkpoint and then answers 1; and "trial element of_", which establishes a checkpoint and then answers the first value from its argument tuple or set. In the latter class is "Try again", which causes the most recent checkpoint to resume and answer a different value. Following "Try again", a previous "first try" will resume and answer false; a previous "trial`#of_" will resume and answer the next natural number less than or equal to its argument; a previous "trial element of_" will resume and answer the next element from its argument. If a checkpoint has already returned every possible value because of repeated sends of "Try again", then it becomes invalid and the next most recent checkpoint is resumed. If no checkpoints are active within the nearest "Backtracking fence_", then "Try again" raises a no-checkpoint exception. Use of a backtracking primitive outside of a function dynamically guarded by "Backtracking fence_" will raise a no-backtracking-fence exception. The unit test, new-avail/Avail/Foundation Tests/Backtracking Tests, includes the archetypal N queens problem, a classical example of the immense power of backtracking:

/* Here's the actual algorithm. Most of it is structure; just a few lines are meat. */ Private method "_queens" is [ n : natural number | queens : ‹natural number…|› := 1 to n; Backtracking fence [ From 1 to n do [ i : natural number | queens := eject queens[i] → trial# of n; From 1 to i - 1 do [ j : natural number | If queens[i] = queens[j] then [Try again]; If |queens[i] - queens[j]| = i - j then [Try again]; ]; ]; ]; queens ] : ‹natural number…|›; /* Make the type really strong. */ Semantic restriction "_queens" is [ n : natural number's type | ‹‹›, [1..⎡n⎤]…|n› ]; Test "eight queens" in backtracking test suite is [ solution : ‹[1..8]…|8› := 8 queens; Require: ‹1, 3, 5, 2, 8, 6, 4, 7› = solution; ];

Many more things are cooking. More on those as they become ready for consumption.

Return to Newsletters | Next ›