Basic Syntax
identifiers
Identifiers can (currently) use
A-Za-z
0-9
_
Other special characters such as ~@#$^&;?
should not
be used since they may be used in the future.
Whitespace is not significant, but is not allowed inside of indentifiers, since they are used for tokenization.
numbers
Numbers are the same as in most programming languages (integer, floating point, hex). Octal is not supported. Binary is not currently supported (may revisit).
-? [0-9]+
ex: 42
-? [0-9]+ . [0-9]*
ex: 42.42
decimal e integer
ex: 42.42e42
0x [0-9] [A-F] [a-f]
ex: 0xFFAAbb. Maybe also use # to indicate hex?
Underscores may be placed anywhere within numbers to help with readability. They will be stripped before evaluation.
42_000_000
is easier to read than 42000000
Units are word suffixes. They may or may not be separated from the number part by a single space. Separating by newlines is not allowed.
strings
Single, double, and back quotes are all allowed for creating text literals. There is no distinct character type. smart quotes or curly quotes will be replaced with their standard equivalent.
Operators
Boolean Operators
<
less than
>
greater than
<=
less than or equal
>=
greater than or equal
=
equal
<>
boolean NOT equal
!=
boolean NOT equal? What about unicode: ≠
and
boolean AND
or
boolean OR
not
boolean NOT
Math Operators
+
add(a,b), addition
-
sub(a,b) subtraction
*
mul(a,b) multiplication
/
div(a,b) division
**
pow(a,b) exponentiation
-
neg(a) negative sign (depending on context)
!
fact(a) factorial
mod
mod(a) modular (remainder ) division. %
is used for percentages
All the rest
()
parenthesis for grouping and function calls
[]
square brackets for list literals, maps to list(a,b,c,...)
function
<<
assign
>>
assign and pipeline operator (depending on the context)
as
convert to a specified unit. ex: 10cm as inches
. works on lists.
Specifically Excluded
<<
>>
|
&
--
-=
+=
++
1..10
, 1..<10
and other comprehensions (may revisit)
mod
instead
{}
are currently not used and are often harder to type on non English (QWERTY) keyboards.
Functions
Definition
Functions are named by standard identifiers. They are called using parenthesis with one or more arguments. Arguments may be referred to by position (indexed) or name (keyword).
Consider the chart
function.
myfun << (data:?, type:'point', color:'red') -> { }
myfun
is an identifier. A function which takes x and y is
declared and assigned to myfun. Essentially all functions are
anonymous functions. Each argument includes a default value.
The default of '?' means it has no default and must be provided
by the caller.
Parameter Resolution
The arguments may be called by order or name. ex:
call by order
myfun( [1,2,3], 'point', 'red')
call by keyword
chart( data=[1,2,3], color='red')
call by order and keyword
chart( [1,2,3], color='red')
Parameter resolution is as follows.
pipeline operators
The <<
and >>
operators are called pipelines. They take something and pass it into something else.
They are used to assign values to variables, and to pass the output of one function into the
first parameter of the next.
assign 42 to answer
answer << 42
42
is the same as
42 >> answer
42
pass the output of range into the print function
range(10) >> print()
is the same as
print(range(10))
Control Flow
If statement
The if statement works as follows
if
keyword followed by a boolean expression, followed by then
, followed by a block.
else
block.
ex:
if (x = 5) then { 5 } else { 10 }
using single expressions
if x = 5 then 5 else 10
the if statement itself is an expression, so it's result can be assigned to a variable or used inside another expression
x << 56 is_even << if x mod 2 = 0 then true else false
=================
notes
if( test: exp, then: exp exp exp, else: exp exp exp )
is_even << if( test: x mod 2 = 0 then: true else: false )
is_even << def (x:?) -> start x mod 2 = 0 end
Match statement
Still being defined. I'm leaning towards something like
match x start 5 -> expression 6 -> expression x when x < 5 -> expression end
Misc
Unicode operators and identifiers
While any unicode characters can be used in strings and identifiers, these will likely have special support in the interface to make them easier to enter. They will also be shown in their unicode form in the "print ready" syntax.
ø
or θ
Issues
I'd really like to get rid of the curly braces for blocks. I'm not sure how to do that. The
if statement already has delimiters in the form of then
and else
. By adding end
I
could get rid of the braces. I don't know about function definitions and match expressions
yet.
Match could be
match exp start exp fun exp fun exp where exp fun else exp end
if could be
if exp then exp exp else exp exp end
Function definitions could be
myname << define args start exp exp exp end
Unicode stuff isn't working in docs. I don't know why. The symbols always get garbled. Ideally you'd write with some sort of abbreviation and the editor would immediately replace it with the unicode form.