Example program:
{"Hello, World!"!;end}
More examples below: [ Extended Examples ]
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; end} };
count{ n=n+1;end}
setType{type=$@1;end}
type="";
count=1;
Here is a simple one scenario program describing a simple calculation
{delta = b*b - 4 * a * c; end}Here is another
{tmp=a; a=b; b=tmp; end}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; end | delta>0; realRoots; end | delta<0; complexRoots; end };
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 | end}
(if_then_else_selection): { condition; ifTrue; end | ifFalse; end }
(for_loop): { index=first; {condition; body; index=next; repeat | end}; end}
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 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; end | n even; n=n/2; repeat| n=n*3+1; repeat}
sum={s=0; n=1; { n>$@#; s | s=s+$@n; repeat }; s}
{d>0; d=d-a; end| d=d+b; end}
{n<=0; end| n=n-1; oneStep; repeat}
Bresenham={a=?;b=?; d=?; n=?;
{n<=0; end
| n=n-1;
{d>0; d=d-a; diagonal; end
| d=d+b; axis; end
}
repeat
}
}
An incomplete class for handling fractions like 1/2 and 37/48:
Fraction={numerator=0; denominator=1;
set_numerator{numerator=$;};
set_denominator{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 |
. . . |