Z^3 Language Documentation
Motivation
The power of a language is almost entirely in the notations and simplifications that are provided. Kenneth Iverson in his paper (http://www.eecg.toronto.edu/~jzhu/csc326/readings/iverson.pdf Notation as a Tool of Thought) details the importance of good notation to assist making thought easier.
z^3 expands on Javascript notations, and then enhances the notation to allow easy expression and simplicity.
Assignment Operators
z^3 allows assigning values to the left as well as to the right using <== and ==> operators. This allows better expressivity for more logical thinking.
a <== 23; 23 ==> a;
a <== 23; is equivalent to a=23; and both notations are equivalent in z^3.
:= : Quick Function Creation Operator
The quick function creation operator in z^3 ( := ) is similar to the => operator in Javascript. However, the advantage of := operator is that the parameters are not named explicitly (and is autodetected). For example to define a function such as v=u+a*t, v:=u+a*t is sufficient, and the parameters u, a and t are auto detected.
Any variable names with lowercase (such as ab, cde, etc) with less than 3 characters in length, is considered to be a local variable. All other names (including any longer variable lowercase names) are checked to see if there is a similar name already in a higher or global scope, and in which case, will not be treated as a local variable.
The => function definition operator in normal Javascript, differs slightly. Hence to define a function such as v=u+a*t, in Javascript (as well as z^3), it would require us to indicate it as v=(u,a,t)=>u+a*t;
The := operator in z^3 hence allows avoiding explicitly repeating the parameter names again in the argument list and function body.
v:=u+a*t and v=(u,a,t)=>u+a*t; both are equivalent to
function v(u,a,t)
{
return(u+a*t)
}
Operators
@: Function Apply Operator
1..100@SIN
~: Transpose Operator
[[[1..10]~]~]~
↑ and ↓: Ascending and Descending Operator
MAGICSQUARE(5)! (1..100)↓ (1..100)↑
⧓,⧒,⧒ and ⋈: Between Operators
a=-1; ⧓(1,a,30) a=29; ⧓(1,a,30) //between g a=31; ⧒(1,a,30) //xlbetween g a=30; ⧒(1,a,30) //xlbetween g ⧒(1,2,30) // xlb g ⧒(1,1,30) a=29; ⋈(1,-1..31,30); ⧓(1,-1..5,4); [ ⧓(1,1,30), ⧓(1,0,30), ⧓(1,10,30), ⧓(1,31,30), ⧑(1,29,30), ⧑(1,30,30), ⧑(1,1,30), ⧑(1,30,30), ⋈(1,1,30), ⋈(1,3,30) ]
√: Square Root, Cube Root, Fourth Root and Nth Root Operators
√(3+34) ∛(27.01) √√64 ROOTNTH(1..10,4) // root is first parameter NTHROOT(1..10,4) // root is second parameter NTHROOT(1..100,2) NTHROOT(1..100,4) ROOTNTH(1..100,2) ROOTNTH(1..100,4) 3√81
Logical Statements
If Statements
a=3;
(a<0)::{"whatever"},
{
!(a>4)::
{"whateverelse"},
{"whateverelseleft"}
}
(a>4)::
{"whateverelse"},
{"whateverelseleft"}
(b<0)::b=34,b=345;
is equivalent to
if(b<0)
{
b=34;
}
else
{
b=345;
}
Both notations are equivalent and will work in z^3.
Switch Statements
Apart from the conventional Javascript switch statement syntax, z^3 enhances language simplicity with a new style.
The new z^3 switch statements syntax is as follows.
discriminant:::
{
x, y::
/*statements to be executed if x or y is true*/
/*Break is automatically added. */
/*Simply add an empty statement using a simple extra semicolon (;)) */
,
z::
/*statements to be executed if z is true*/
,
default::
}
For example,
b=0;
c=343;
fruits="mango";
fruits:::
{
"apple","tomato"::
b++;
c=3.4;
,
"mango"::
b=34905;
,
default::
b=45.6;
}
[b,c];
switch(a)
{
case b:
case c:
break;
default:
break;
}
Both notations work in z^3
Loops
a=1;
do
{
a++
}
until(a>20); // do while(!condition)
a; // here this will be 21, since !condition is checked like a do while loop.
a=11;
b=45;
because(a<b)
{
a++
OUTPUT(a)
}
a=11;
do
{
a++
}
unless(a==11);
a;
Function Declarations
function y(x)
{
∵(x<345)
{
∴(x+3434)
}
∵(x>345)
{
∴(x-3434)
}
}
y(13);
The letter Ƒ can also be used instead of the full term function.
Ƒ y(x)
{
∵(x<345)
{
∴(x+3434)
}
∵(x>345)
{
∴(x-3434)
}
}
y(13);
Existential Quantification
a=1..100;
∀a("x<810")
∃a("x<810")
∄a("x<810")
a=1..100;
[∀a("x<810"),∃a("x<810"),∄a("x<810")]
a=1..100;
[∀a("x<810"),∃a("x<810"),(!∄a("x<0"))]
a=1..100;
b= ∀a("y*2<200");
b.result
a=1..100;
b= ∀a("y*2<=50");
a.pick(b.result)
//make a pick operator based on a similar array of true false. or non-existant to get the values out.
//PICK
a=1..100;
b= ∀a("y*2<50");
a.pick(b.result)
List of Operators
+, -, *, /, ^, % - Arithmetic Operators
| | - Array Function and Creation Operator
.. - Arithmetic and Geometric Series Creation
... - Arithmetic and Geometric Series Creation
@ - apply to
# - Series or Special Case Qualifier for Dates, Calci Cells, and Sequences, etc.
## - Prefix used to indicate long variable names with spaces.
(e.g., ##Speed of the Car=34, which gets translated to SpeedoftheCar = 34;)
<<< - Member or Variable Assignment
() - Function Call
[] - Set Creation
- Object Set
- Set Object Membership
. - Member Function Dereferencing.
. mf - Member Function
.$ mf(function, parameters) - Element-wise Function Application
.$$ mf (special – Row-wise Function Application
.$$$ mf (special) – Column-wise Function Application
.$_ mf (special) - Cumulative Function Application (all)
:: - If
::: - switch
= - Assignment to the left
<== - Assignment to the left
==> - Assignment to the right
:= - Quick function definition operator.
All operators in Javascript, also have the same meaning in z^3, except binary operators such as |, & and ~.
Binary | is used to indicate matrix boundaries, and is replaced with |||.
Binary & is used to indicate matrix boundaries, and is replaced with &&&.
Binary ~ is used to indicate matrix boundaries, and is replaced with ~~~.
Short Cut Keys
CTRL+G - to convert into Greek Code CTRL+U - Converts SIGMA to Σ SHIFT+ENTER- Gives Parameter Expansion Double tap SHIFT - Toggle Capital and Small Letter [Ex: Convert FRACTAL to fractal and vice verse] CTRL+SPACE - Function Listing