Tuesday, January 08, 2008

[Protium] Master Class #1 (Part 2)

Demonstration - Oblique Strategies

"The Oblique Strategies are a deck of cards. Up until 1996, they were quite easy to describe. They measured about 2-3/4" x 3-3/4". They came in a small black box which said "OBLIQUE STRATEGIES" on one of the top's long sides and "BRIAN ENO/PETER SCHMIDT" on the other side. The cards were solid black on one side, and had the aphorisms printed in a 10-point sans serif face on the other.


The deck itself had its origins in the discovery by Brian Eno that both he and his friend Peter Schmidt ... tended to keep a set of basic working principles which guided them through the kinds of moments of pressure — either working through a heavy painting session or watching the clock tick while you're running up a big buck studio bill. Both Schmidt and Eno realized that the pressures of time tended to steer them away from the ways of thinking they found most productive when the pressure was off. The Strategies were, then, a way to remind themselves of those habits of thinking — to jog the mind."         
-- Oblique Strategies
A web-based installation of Oblique Strategies is supplied in the standard Protium install. Using the "Internet Information Services" snap-in, create a virtual directory pointing to C:\protium\Code\prx\os. Specify its default as index.prx, call it 'os', and share the C:\protium\Code\prx\os directory (Microsoft Access is picky about being able to write to databases even when only reading.)

Further information on setting up IIS can be found in the Protium document "C:\protium\bin\plugins\Configuring Windows IIS 5 to use with Protium and Isis.html"

The Protium code in the index.prx file is as follows:
The above code (indented only to more clearly demonstrate document structure) outputs a different strategy each time the page is refreshed. The syllables translate as follows:
<@ DEFKEYLIT>__Transput|__HTMLTransput</@>define the Transput as HTML
<@ SAYPRO>output a document prologue. (What is output by the PRO syllable depends on the Transput defined, as is the case for all document related syllables.)
<@ SAYDOC>Enclose a document.
<@ SAYDHD>Enclose a document header, in the context of an existing document.
<@ SAYDTT>Oblique strategies</@>set the document title, in the context of an existing document body and header.
<@ SAYDBD></@>enclose a document body, in the context of an existing document.
<@ DEFDBFLIT>os</@>opens this data source, by default a JET/MSAccess database.
<@ DEFRSTCAP>select * from os where cardid = <@ SAYRANLIT>100</@></@>Open record source defined by captured output.
<@ SAYRANLIT>100</@>return a random number between 1 and 100.
<@ SAYDPR></@>enclose a document paragraph, in the context of the existing document.
<@ SAYFLD>message</@>print the contents of the field called 'message' which, in this context, is part of the 'os' recordset.
Note that the code chooses a strategy based on a random number between 1 and 100. But what if there are more than 100 strategies? Wouldn't it be better if the actual number of records could be found and that used as the basis for the RAN syllable? Two ways of handling this requirement are described below:

The changed syllables translate as follows:
<@ DEFRSTLIT>os</@>Select every record in the database.
<@ LETVARSZERST>upper|___</@>assign to the variable 'upper' the size of the default (marked by three underscores) recordset.
<@ RSTCAP>select * from os where cardid = <@ SAYRANVAR>upper</@></@>Select a new recordset, capturing the output from RAN but using the variable 'upper' to specify the limit.
Rather than get the number of records, simply ...
<@ ACTMOVRANRST></@>move the record pointer to a random place in the recordset.
This demonstrates the power of idiomatic Protium: short, sweet and to the point.

Questions and Answers

I can't see a main() anywhere. Where's the start?

Protium implements a single-pass code evaluation model. This is quite unlike most other languages which implement double-pass code evaluation: first pass to discover and make a map; second pass to evaluate.

Protium starts at the beginning of a named file, and builds its awareness of context from there. Because of this approach, we may never examine code we aren't interested in.

I keep using the same construction over and over again. Is there a way of abbreviating Protium words?

What you can do is create a compound operator (a concept borrowed from OPS-3). These are defined using the KOP syllable. If you wanted to define LVK as a shorthand for LETVARKEY, for example, then you would code

Thereafter you would be able to use the abbreviated form, replacing code like

There are other ways of doing this, including UDS (user-defined syllable) and BLK (code block), but this is by far the simplest.

*** End of Part 2 ***

© Copyright Bruce M. Axtens, 2008

No comments: