An experimental hobbyist language with a focus on events.
FuncE: The Functional Event Language Version 0.1
Leading whitespace-significant. 4 spaces = 1 tab.
Prefer capitalization:
- Types and Events: Pascal
- Functions and fields: camel
var- declares a varying field or localnew- declares a non-varying field or localset- changes a field or local's value to the RHS at the time of evaluationlet(not in this version) - changes a field or local's value to always reflect the RHSpure- handler or function always returns the same value for the same input; it does not reference global statethen- after handling the event previously specified, handle this eventif- evaluates a Bool expression; if true, continue into next indent, otherwise skipelse- paired withif, allows different indent if the condition was falseelse if- paired withif, allows another Bool expression to be evaluated recursivelyloop- loops by a condition, optionally with a repetition instructionreturn- exits a function returning the specified value
var Int32 charactersEntered = 0;
var Int32 linesEntered = 0;
var Int32 minCharacters = 2000;
var Int32 maxCharacters = 0;
pure Enter<>
LineOut "Init with: " + paramLine; // implicit use of event's parameter
then LineOut "Type lines, or type an empty line to quit.";
LineIn<line.Count != 0>
set charactersEntered += line.Count;
set linesEntered++;
if {minCharacters < line.Count < maxCharacters}
LineOut "Fitting in!"
if line.Count < minCharacters
set minCharacters = line.Count;
if line.Count > maxCharacters
set maxCharacters = line.Count;
LineIn<line.Count == 0>
new mean = getMean(charactersEntered, linesEntered);
new range = minCharacters + (maxCharacters - minCharacters);
new toWrite = "
Finished. You wrote" + charactersEntered + " chars, over " + linesEntered + " lines.
That's " + mean + " characters per line! Range is like " + range "!
"
LineOut toWrite
then Exit 0
pure Dec128 getMean(Int32 sum, Int32 numEntries)
return sum / numEntries;
- Object
- Number
- Int32, Literal:
0or[1-9][0-9]* - Dec128, Literal:
[1-9][0-9]*.[0-9]+or0.[0-9]+
- Int32, Literal:
- Number
- Bool, Literal:
falseortrue - String, Literal:
- Global Field
[var|new] type id = initialValue
- Handler
pure? eventType<restriction?>
- Function
pure? returnType id(params)
- Event Raise
then? eventType parameter parameter;
- Assignment
[set|let] id = newValue;set id += newValue;(or-=)set id++;or--
- Local declaration
[var|new] type? id = initialValue;
- Conditional
if boolExpression \t bodyif boolExpression \t body1 un-\t else \t body2(and else if)
- Loop
loop (condition) \t bodyloop (condition; statementsAfterContinue) \t body
- Return
return expression
- Object orientation (left)
- Method call
id(params)-> whatever type the method returns - Member access
id.id2-> whatever type the member is
- Method call
- Factorwise (left)
- Multiplication
Int32 * Int32-> Int32Int32 * Dec128orDec128 * Int32-> Dec128Dec128 * Dec128-> Dec128
- Division
Number / Number-> Dec128
- Integer division
- Same as division, but with operator
/iand always returnsInt32
- Same as division, but with operator
- Multiplication
- Termwise (left)
- Addition
- Same as multiplication, but with operator
+
- Same as multiplication, but with operator
- Subtraction
- Same as addition, but with operator
-
- Same as addition, but with operator
- String concatenation
Object + StringorString + Object-> String
- Addition
- Comparison (left)
<=>=<>Number op Number-> Bool{Number <= Number <= Number}-> Bool
==!=Object op Object-> Bool
- Logical Combination (left)
!!Bool-> Bool
&Bool & Bool-> Bool
|Bool | Bool-> Bool
^Bool ^ Bool-> Bool
Assignment is a statement type, not an expression. Bitwise ops are not language features.
- Bool
true - Bool
false
- Enter
- Exit
- LineIn
- LineOut
- Exit: stops execution with the specified exitCode
- LineOut: prints line and an endline character to stdout
- On app startup, emit
Enterwith paramLine being the args on command line - On new line of input from stdin, emit
LineInwith line being that line
let(reactive)- User-defined events/types
- Other predefined types
- Smarter/configurable event dispatching
- Domains
- Call only one handler
- Waiting for handler before continuing execution (await)
- Multithreaded handlers
- Exceptions
- Multiple files
- Compilation instead of interpretation
- .NET Interop
- Aggregate types (arrays, lists, etc.)