A new spin on programming
This is Pivot, a scripting language designed to make programming a more enjoyable experience. Pivot is developed with the user in mind and has speech-like logic syntax structure. The core team aims to build a feature rich language that can serve both expert and novice programmers alike.
Inspired by programming languages like JavaScript, F#, and Python, Pivot features syntax and semantics designed with an effort to be simple while still preserving the complex, logical features that make these languages so great.
- Statically typed with some auto type inference
- Strongly typed
- Scripting
- Impure functional language
Pivot is created by @Will DiBiagio, @Jigar Swaminarayan, @Manny Barreto and @Nicolas Raymundo.
- Contents
- Types
- Operators
- Comments
- Pivot Examples
- Semantic Errors
- Optimizations
- 📄 License
- Strings:
str
- Characters:
char
- Booleans:
bool
- Numbers:
num
- Auto:
_
- Lists:
[type]
- Dictionaries:
{type:type}
Operation | Type Compatibility |
---|---|
Add + |
Strings, Numbers, Lists |
Subtract - |
Numbers |
Multiply * |
Numbers |
Power ** |
Numbers |
Divide / |
Numbers |
Modulus % |
Numbers |
Strict Equality == |
Strings, Numbers, Lists |
Less than < |
Strings, Numbers |
Greater than > |
Strings, Numbers |
Less than or equal <= |
Strings, Numbers |
Greater than or equal >= |
Strings, Numbers |
Logical AND and , && |
Booleans |
Logical OR or , || |
Booleans |
Operation | Type Compatibility |
---|---|
Negative - |
Numbers |
Negation ! , not |
Booleans |
- Single line:
//
- Multi-line:
/* */
str name <- "Jigar";
_ age <- 21;
bool below6ft <- true;
[str] animals <- ["dog", "cat", "pig"];
all num a, b, c <- 1, 2, 3;
{str:num} ages <- {"john" : 5, "tim" : 6};
num pow4 -> num default ** 4;
Call chain with a built-in task or user defined task
print (-33) >> abs >> pow4;
add5(num x) -> num
return x + 5;
end
add5(10);
num x <- 3.1415;
if x > 3 then print "larger than 3"; end
num x <- 3.1415;
if x > 3 then
print "larger than 3";
else
print "less than 3";
end
num x <- 32102123;
str msg <- "hello" when x % 3 == 2 otherwise "bye";
for num x <- 0; x <= 10; x <- x + 1 do
print x;
end
num x <- 25;
while x do
print x;
x <- x - 1;
end
num x <- 30;
repeat
print x;
x <- x - 5;
when x == -30 end
{str:num} ages <- {"john" : 5, "tim" : 6};
ages:"john" // 5
Yet to be implemented
contains(keyId)
contains keydel(keyId)
delete pair by keykeys
list of keysvalues
list of values
ages::keys // ["john", "tim"]
ages::values // [5, 6]
ages::contains("michael") // false
ages::del("john") // {"tim" : 6}
[str] friends <- [ "john", "tim", "steve" ];
friends:1
friends:1...3
head
first elementtail
last elementlen
number of elementsfind(elemId)
index of elementpush(elem)
add to the end of a listpop()
remove from the end of a listunshift(elem)
add to the beginning of a listshift()
remove from the beginning of a list
friends::head() // "john"
friends::tail() // "steve"
friends::len() // 3
friends::find(tim) // 1
[str] friends <- ["john", "tim"];
friends <- friends + ["alex", "sasha"];
print friends; // ["john", "tim", "alex", "sasha"]
findMin([num] arr, num low, num high) -> num
if high < low then return arr:0; end
if high == low then return arr:low; end
num mid <- (low + high)/2;
if mid < high and arr:mid+1 < arr:mid then
return arr:mid+1;
end
if mid > low and arr:mid < arr:mid-1 then
return arr:mid;
end
if arr:high > arr:mid then return findMin(arr, low, mid - 1); end
return findMin(arr, mid + 1, high);
end
function findMin(arr, low, high) {
if (high < low) {
return arr[0]
}
if (high == low) {
return arr[low]
}
let mid = (low + high)/2
if (mid < high && (arr[mid+1] < arr[mid])) {
return arr[mid+1]
}
if (mid > low && (arr[mid] < arr[mid - 1])) {
return arr[mid]
}
if (arr[high] > arr[mid]) {
return findMin(arr, low, mid-1)
}
return findMin(arr, mid+1, high)
}
fibonacci(num x) -> num
all num a, b, temp <- 1, 0, 0;
repeat
temp <- a;
a <- a + b;
b <- temp;
x <- x - 1;
when num == 0 end
return b;
end
function fibonacci(x) {
let a = 1, b = 0, temp = 0;
do {
temp = a;
a = a + b;
b = temp;
x--;
}
while (!(x === 0));
return b;
};
evenOdd(num x) -> bool
return x % 2 == 0;
end
function evenOdd(x) {
return x % 2 == 0;
}
gcd(num a, num b) -> num
return a when !b otherwise gcd(b, a % b);
end
function gcd(a, b) {
return !b ? a : gcd(b, a % b);
}
firstFactorial(num x) -> num
if x == 0 or x == 1 then return 1; end
return x * firstFactorial(x - 1);
end
function firstFactorial(x) {
if (x == 0 || x == 1) {
return 1;
}
return x * firstFactorial(x - 1);
}
- Type mismatch in declaration
- Variable already declared
- Variable assignment type mismatch
- Variable not yet declared
- Non-existing function call
- Incorrect number of function parameters
- Mismatched function return type
- Types are not compatible
- Function missing return statement
- Arithmetic with undefined variable
- Invalid types used with addition
- Invalid types used with multiplication
- Invalid types used with subtraction
- Invalid types used with division
- Incorrect use of unary operator
- Inconsistent list types
- Invalid variable type
- Break outside of loops or task
- Deterministic condition
- Invalid dict types
- Unreachable statement
- Inconsistent dict expression types
- Negation of
BoolLiteral
andNumericLiteral
- Arithmetic expressions
- Relational expressions
OR
operationsAND
operations
- Returning either the
expression
oralternate
if thecondition
can be evaluated
- No op optimization
Pivot is MIT licensed, as found in the LICENSE file.