Future Syntax of Roman
Starting with the basic syntax grammar, we have some ideas on how Roman will look like once we add in some more syntax primitives. For completeness, we will start from the beginning.
Comments --
One liner comments start with --
Multi-line comments have ---
at the beginning and end.
! The Roman proclamation operator and ? the query operator
Roman uses .
to create definitions or assertions or declarations.
x = 5 . -- make a definition
: OK
y > 5 . -- Assert as a fact that y is greater than 5.
: OK
y > 5 ? -- Query if y is greater than 5. Prolog like logical deduction
: OK, True
y = 6 ? -- Query if y is 6
: N/A, I'm not sure
For explicit RPN or pre-fix notatoin, we have | pre-fix and : RPN notations
Brackets are necessary as these operators have to be in the last position.
( 3 4 + :) -- 7
( + 3 4 |) -- 7
-- both are equivalent to
( 3 + 4 . )
-- or
3 + 4 .
Functions and Macro definition and the |> pipe operator
(x) => (x x *). -- anon function
square = x => (x x *) . -- def function
add10 = x => (x 10 +) . -- another example
plusplus = (x) ~> (x 1 +) . -- Macro definition
2 square -- calling a function
: OK, 4
2 square |> add10
: OK, 14
Conditionals
If else
x if ( x > 0 ?) else -x .
a = x if (x > 0 ? ) else -x .
Pattern Matching
s = "MON".
s matches
"SUN" -> "SUNDAY"
"MON" -> "MONDAY"
_ -> "PICK A DAY".
: OK, "MONDAY"
day =
s match
"Sun" -> "Sunday"
"Mon" -> "Monday"
_ -> "Pick a day" .
Conditionals
truth : string, -- type inference declared below.
truth = "Default truth" unless
( 2 2 +) = 5 ? ~ "This is not true"
(2 2 + ) = 4 ? ~ "This is true" .
truth : string ?
: Ok, True
Type Inference
truth : string,
truth : string ?
: Ok, True
square : number number -> number .
square : integer | float , integer | float -> integer | float .
square : (A : integer | float) , A -> A .
A : integer | float. -- "Let A be a customer type of integer or float, union type declaration. similar to `type` keyword in elm"
A : { name : string, age : integer }. -- "A is a struct of shape...an alias(type). Similar to structure or `type alias` in elm".
Concept of holes, in-complete expressions that the user will update later
We use the semi-colon to denote a Roman expression that's incomplete and which the user will come back to later.
square = (x) => () ;
: Ok, Waiting
square = (x) => () .
: Error, empty function body in declaration
Tensors, a generalization of Arrays in Roman
[ 1 2 3 4 5 6 7 8 9 | (3 3) ] -- A tensor with shape 3, 3, that's a 3x3 matrix
A = [ 1 2 3 4 ] -- an array A with assumed shape (1). Equivalent to [ 1 2 3 4 | (1)]
A[0] : 1 -- 0 based indexing
A[1] : 2
A1 : 1 -- 1 based positional access. number at end of a variable is assumed to be a positional of the array (or tensor) A
[1 2 3 4 5 6 7 8 | (2 2 2) ] -- A tensor of shape 2x2x2, a data cube with 2x2 matrix and two "layers"
[ 1 2 , 3 4 ] -- Equivalent to [ 1 2 3 4 | (2 2)] a square matrix 2x2. Commas separate rows.
[ (1 2 , 3 4) (5 6 , 7 8) ] -- same as the tensor above 2x2x2
[ (1 2, 3 4) (5 6, 7 8) , (9 10, 11 12) (13 14 , 15 16)] -- is a 2x2x2x2 tesseract (array -> matrix -> cube -> tesseract)
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | (2 2 2 2)] -- same as above, called the longform of the tensor.
Collections
Roman has four type of collections.
() -- list or n-tuples, generic. Use index to access. is type inferred (can be any) (heterogeneous)
{} -- A map structure use a index or keyname to access heterogeneous, has a type alias declared
[] -- tensor, ordered, can use index to access, homogeneous
|[ ]| -- table, like lua table, a set of vectors that has a type alias declared and use an index AND keyname to access, homogeneous list of heterogenous vectors.
[] can be thought as {} with integers as key coresponding to it's position
Package
ParserBehavior contains behavior.
ParserBehavior packages
parse : string -> (Ok, oexp) | (Error, string).
extensions : () -> string array.
end
SizeTrait contains trait,
& packages
size : @ -> number.
end
Rome adopts ParserBehavior,
& uses OmicronModel,
& derives SizeTrait for RomanDataModel,
& arranges ConnectionScore ,
& composes EntityPackage,
& uses Utilities as UtilsPackage,
& opens (Core, OS, Network),
& opens DefaultBundle. -- similar to Rust's preludes
Rome packages
RomanData : {
r : oexp
o : oexp
m : oexp
e : oexp
}.
R : RomanData,
R = {
r = reader
o = observer
m = modeler
e = evaluator
}.
R2 : RomanData ++ MyData . -- concatenates two structs.
parse = (s) => ( s " world" ++ :), -- concatenates two strings
extensions = () => (["oexp", "markdown"]) .
size : RomanData -> number,
size = (data) => (10 4 * ) . -- fixed size of 40 for any data
end
ModuleSpec aka Behaviors aka Interface
A list of functions that a mod declares the intent to implement
ComponentSpec implements the Model :with Traits and Schema
States that this mod will implment a variant of a function that
ConnectionSpec
how an entity embeds/integrates within the system. System here is analogus to Supervisor in Elixir
IdentitySpec
how the entity is identified and created.
Entity Module Component System
Entity: a "live" object in the program Module: a set of functions implementing behaviors that the entity and compose Component: a set of models an entity can compose System: A way of Entity to be embedded, connected and have it's end-life time controlled by the whole program (supervisor scheme).
! ping operator to send async messages
eid portid message ! -- send "message" to entity eid via our output port portid