A simple statically typed language that should be easily compiled to dynamically typed languages
Entities should not be multiplied unnecessarily.
-- William of Ockham
For example, many languages has these entites
- variables
var foo = 1; var bar = 2; - parameters
function (foo,bar) { return foo + bar; } - objects
{foo : 1, bar : 2} - tuples
(1,2)
Oczor uses records instead of all these entities
| Oczor | JavaScript |
|---|---|
x1 = 1
x2 =
foo = 1
bar = 1
func x y = x + y + 1
x3 = func 1 2
func2 x =
temp = x == 1
in not (temp && false)
|
var x1 = 1;
var x2 = {
foo : 1,
bar : 1
};
var func = function(x,y){
return x + y + 1;
};
var x3 = func(1,2);
var func2 = function(x){
var temp = x === 1;
return !(temp && false);
}; |
Most syntax constructions have two options - comma or indent separation
| Comma | Indentation |
|---|---|
x = (foo = 1, bar = 2)
type Cat = name : String, age : Int
|
x =
foo = 1
bar = 2
type Cat =
name : String
age : Int
|
x = (foo = 1, bar = 2)print x.foo
print x.bary = x with (foo = 2)Tuple is a record with labels itemN
x = (2,3)same as
x = (item1 = 2, item2 = 3)Destructuring assignment
x = (2,3)
(y,z) = x
print yx = (foo = 1, bar = 2)
(foo = y, bar = z) = x
print yx y => (x,y) or \x y => (x,y) -- \ is optionalfunction definition is a syntax sugar for a label with anonymous function
foo x y = (x,y)same as
foo = \x y => (x,y)z = foo 1 2For example, it is possible to group functions like this
bar =
foo x y = (x,y)
id z = zbar.foo 1 2
bar.id 1Parameters can be matched with literals, tuples, records or external variables
x = 1
foo = case
1 => 2
(x,2) => 3
(foo = x, bar = 3) => 4
^x => 5inc : Int => Int
inc = add _ 1
x = inc 1function eqAny(x,y) {
return x === y;
}ffi eqAny : a, a => Boolinfix == 4 eqAny
x = if 1 == 2 then 1 else 2 type Cat =
name : String
age : Intcat = (name = "Tiger", age = 25)type Number = Int | Double
x : Array Number
x = [1, 2.0, 3]ffi eqInt : Int, Int => Bool
ffi eqString : String, String => Bool
class equal a : a => Bool
instance Int equal x y = eqInt x y
instance String equal x y = eqString x y
infix == 4 equal
x = 1 == 1
y = "foo" == "foo"Alpha/Experimental
-
Install stack.
-
clone or download this repository
-
In project directory run
stack setup stack installstack installwill install the occ executable into ~/.local/bin, which you should add to your PATH.
-
create a directory
hello -
copy
stddirectory fromlibsdirectory -
create a file
hello.ocimport std print "hi" -
run
occto compilehello.ococc hello.ochello.jsshould be inoutputdirectory -
hello.jscan be run with nodenode output/hello.jsshould print
hi -
occ --helpto display the compiler options