[Inquiry] Re: Theme One Program -- Commentary Notes

Jon Awbrey jawbrey at oakland.edu
Tue Mar 18 19:26:52 CST 2003


o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o

TOP.  Commentary Note 9

o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o

Trap.

Trap is a function from text files and ideas to ideas.
It takes a character off the input stream and assigns
it to the 'sign' field of a significant argument idea,
or reports out a nil idea if its argument idea is nil.

Nota Bene.  In this version of Pascal, variables with file types,
for example, text files, must be declared as variable parameters.
One way to think of variable parameters in functional terms is to
regard them as being listed on both sides of the functional arrow.

In this view, Trap is a function from texts and ideas
to texts and ideas, Trap : Text x Idea -> Text x Idea.

For example, if 'thou' has a legitimate character next in line, say "a",
and if 'this' is a non-nil idea, then Trap yields an idea of this shape:

     o-----o
     | a   |
     o-----o
     ^
trap |
     @

function trap (var thou: text;
                   this: idea): idea;
begin
 trap := this;
 if this <> nil then read (thou, this^.sign)
end;

(5217)(7557)

o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o

Part.

Part is a function from text files and ideas to ideas.
It puts a character from the 'sign' field of a non-nil
argument idea on the output stream and reiterates this
idea as its current functional value, thereby serving
as a write operation that copies the authorizing idea
to the functional result.  If the argument idea is nil,
then the write operation is skipped and the functional
value is likewise a nil idea.

Nota Bene.  In this version of Pascal, variables with file types,
for example, text files, must be declared as variable parameters.
One way to think of variable parameters in functional terms is to
regard them as being listed on both sides of the functional arrow.

In this view, Part is a function from texts and ideas
to texts and ideas, Part : Text x Idea -> Text x Idea.

For example, if 'this' is a non-nil idea of the following shape,
then the functional value of part (this) is the very same idea,
with the side-effect of writing "a" to the argument text file.

     o-----o
     | a   |
     o-----o
     ^
part |
     @

function part (var thou: text;
                   this: idea): idea;
begin
 part := this;
 if this <> nil then write (thou, this^.sign)
end;

(5218)(7558)

o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o

Rapt.

Rapt is a function from pairs of ideas to ideas.
Its functional value is a nil idea unless both of
its argument ideas are non-nil and have identical
characters in their 'sign' fields, in which case
its functional value is equal to the second idea.
In this fashion, reporting a nil idea for "false"
and a non-nil idea for "true", it operates as a
primitive test function that will be called as
a basic part of many other equality, look-up,
match, or test functions.

function rapt (that, this: idea): idea;
var here: idea;
begin
 here := nil;
 if this <> nil then if that <> nil then
  if that^.sign = this^.sign then here := this;
 rapt := here
end;

(5219)(7559)

o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o




More information about the Inquiry mailing list