| Date | Event |
|---|---|
| Dec 20 2007 | Preliminary draft proposal |
| Mar 16 2007 | Author creates an improved SOOP2 |
| Apr 07 2009 | Small Corrections ready for CS320 students. |
Example program:
{"Hello, World!"!;}
More examples below: [ Extended Examples ]
Number: Integer values, understands arithmetic operations like addition and subtraction.
String: Finite sequences of characters, understands how to be concatenated, etc.
Boolean: True or false, understands conjunction, disjunction, negation, etc.
Compound: has many parts with "@" and "#" to access them.
Null: has no knowledge or know how except how to accept data and methods.
42
-1
+41
"hello world"
Widgets={type=""; setType{type=$@1;}};
Widget
A class is a list of new data and methods that can be added to an existing object. Al objects know how to extend themselves with new methods and data. So
new Widgetcreates a null object and adds an item of data (type) and a method to change it.
A class is a collection of such methods and data fields. Here is a single an example with one data field and one method:
{type=""; setType {type=$@1; } };
count{ n=n+1;}
setType{type=$@1;}
type="";
count=1;
Here is a simple one scenario program describing a simple calculation
{delta = b*b - 4 * a * c; }
Here is another
{tmp=a; a=b; b=tmp; }
A scenario is, in general, a sequence of commands and methods. A program has many
scenarios that are tried in turn. The later scenarios are called extensions --
see below.
Here is a three scenario program which is part of solving a quadratic equation. It has a main scenario and two extensions.
{delta==0; equalRoots; | delta>0; realRoots; | delta<0; complexRoots; };
A program executes a series of scenarios until one of them completes. A scenario can fail if an expression produces "false" as a final result or if all sub-scenarios fail.
If a scenario fails then the following "extension" is tried in turn.
x=1+2;
(while_loop): { condition; body; repeat | }
(if_then_else_selection): { condition; ifTrue; | ifFalse; }
(for_loop): { index=first; {condition; body; index=next; repeat | }; }
new
n*3+1
n odd
(3,4,1,2)@2
x>0
aStudent drops( aClass )
If the first object is omitted then the object 'this' is assumed as the
default. This has the effect of (1) allowing subprogram calls inside a
class, (2) treating data items in an object as variables.
Objects
(2,3,4)@1 == 2
{a=1; b=2;}@a == 1
| i | c@i |
|---|---|
| i>0 | i'th part of c |
| i==0 | the whole of c |
| i<0 | all parts of c without the i'th part |
(2,3,4)@1 == 2
(2,3,4)@0 == (2,3,4)
(2,3,4)@(-1) == (2,3)
(2,3,4)# == 3
Extended Examples
Here is an object that knows how to count things:
theCount= new { value=0; counts{value=value+1;}; get{value}; }
and here is how it might be used
theCount counts;
theCount counts;
theCount get;The last action returns the number 2.
The following is an object designed to handle loops that count down to zero
countDown= new { value=0; from(value=$@1;); loop{value=value-1; value -1>-1}; }
It is used like this
counDown.set(20); { counDown.loop ; ... ; repeat }
The following creates a new object with two data items and two methods:
widget= new {knobs=0; name=""; addKnob{knobs=knobs+1;}; setID{name=$@1;}};
The following applies the methods to the object.
widget addKnob; widget setID ("ax123c");
wodget= widget{type=""; setType{type=$@1;}};
Extends the widget object by adding a type attribute and an operation
to operate on it.
Conditions and loops
Hailstone={n==1; | n even; n=n/2; repeat| n=n*3+1; repeat}
sum={s=0; n=1; { n<=$@#; s=s+$@n; repeat }; s}
{d>0; d=d-a; | d=d+b; }
{n>0; n=n-1; oneStep; repeat}
Bresenham={a=?;b=?; d=?; n=?;
{n>0; n=n-1;
{d>0; d=d-a; diagonal;
| d=d+b; axis;
}
repeat
}
}
An incomplete class for handling fractions like 1/2 and 37/48:
Fraction={numerator=0; denominator=1;
setNumerator{numerator=$;};
setDenominator{denominator=$;};
set{numerator=$@1;denominator=$@2;};
*{new Fraction set (numerator * $@numerator, denominator * $@denominator)};
. . .
}
. . . . . . . . . ( end of section Syntax) <<Contents | End>>
Predefined Messages
| Symbol | Meaning | Class | Parameter | Produces |
|---|---|---|---|---|
| + | addition | Number | Number | Number |
| + | concatenation | String | Number | Number |
| - | subtraction | Number | Number | Number |
| * | multiplication | Number | Number | Number |
| / | division | Number | Number | Number |
| odd | parity | Number | - | Boolean |
| even | parity | Number | - | Boolean |
| ^ | conjunction | Boolean | Boolean | Boolean |
| \/ | disjunction | Boolean | Boolean | Boolean |
| ' | negation | Boolean | Boolean | Boolean |
| ! | output | Number, String, Boolean, | ||
| == | equality | All | same | Boolean |
| <> | inequality | All | same | Boolean |
| < | less than | All | same | Boolean |
| > | less than | All | same | Boolean |
| # | number parts in | Compound | - | Number |
| @ | part | Compound | Number | any |
| . . . |