Block Protocols: an Overview

Protocols are syntactic structures that are recognized by MathScript and are interpreted in specific ways. They are templates that the author may use to do certain things in her script.

We explain what a block protocol is recursively, defining first a
Mathscript Statement.

A Mathscript statement is
:

a command statement terminated with a semicolon (;) for example, Graph sin;

a program or function statement
terminated with a semicolon (;) for example, Myprog("this"); or sin(pi/3);

or a block protocol .

A
Block Protocol is:

a Block : That is, a nonempty sequence of MathScript statements enclosed in curly braces:

{ ... }

a Command protocol : That is a command definition statement of the form:

Command <name> <arglist> { <body> }

Here { <body> } is a
block.

a Program protocol : That is a program definition statement of the form:

Program <name> <arglist> { <body> }

Here { <body> } is a
block.

a Local protocol : That is a type declaration and a local binding statement:

Local <arglist> { <body> }

Here { <body> } is a
block.

a Do protocol : That is, an iteration statement of the following general form:

Do

<initializations>

<exit condition>

<return statement>

{ <body> }

Here { <body> } is a
block.

a Repeat protocol : That is, an iteration statement of the following form:

Repeat <number of times> { <body> }

Here { <body> } is a
block.

an If...Then...Else protocol : That is, a branch-on-conditions statement of the following form:

If <condition> then { <conclusions> } else { <alternatives> }
or simply,

If <condition> then { <conclusions> }

Here, { <conclusions> } and { <alternatives> } are
blocks.

a LISP protocol: That is, an arbitrary LISP expression in the form:

LISP <Lisp s-expression enclosed in parentheses> ;

Delay Protocol

Delays the execution of a block.

The form is:

DELAY <count>

{ <statement>;

<statement>;

...

<statement>

}

  1. GLDraw Protocol

Use GLDRAW to define an OpenGL Actor or Animation The form is:

GLDRAW {

<statement1> ;

<statement2>; ...

<statementN>;

}

The <statements> are any Mathscript expressions including OpenGL statements.

Nested GLDRAWS are not allowed.

After the compilation, OpenGL has a temporary display list and actor. The temporary actor is removed with the Refresh command.

Example: GLDraw { color(255,0,0,255); Solidcube(10); }