Functional Tuple Language
is a language based on a basic structure functional tuple
(tuple
for short) and a basic mapping operator ->
between tuples that maps output of one tuple to next tuple.
With FTL, an application can be written in one expression composed of a chain of tuples with mapping operators in between. Such form is essentially an algebraic expression representing a topology of tuple mapping with mapping rules as tuple elements in form of functions. With such topology, values flow through mapping rules in a tuple and the result is sent to next tuple, and the same process is repeated until the last tuple.
FTL also allows definition of prefix or postfix unary, binary or n-ary operators, making the program more in algebraic form.
Since FTL is in algebraic form, the process of computation can be done through algebraic substitution.
For more information about FTL, see Functional Tuple Language.
A web page for examples can be found at here.
The grammar of FTL is defined in parsing expression grammar, specifically with pegjs syntax.
The pegjs online is a very handy test platform where any FTL
statements can be tested as follows:
- Copy and paste the grammar from
ftl-grammar.pegjs
into left grammar panel denoted as "1. Write your PEG.js grammar
". - Write/paste any
FTL
statements in the right upper panel denoted as "2. Test the generated parser with some input
", and the panel denoted as "Output
" right below will display all parsed tokens for the statements, which can be examined.
The parser ftl-parser.js
is generated by using pegjs
with slight structural change.
With pegjs online, copy and paste the grammar from ftl-grammar.pegjs
into left grammar panel denoted as "1. Write your PEG.js grammar
", and then fill parameters in the lower right panel denoted as "3. Download the parser code
" with options "Use results cache
" checked and choose "Code size
" for "Optimize
". Then the generated parser code can be downloaded using "Download parser
" button.
The generated parser is wrapped into an anonymous function. The actual ftl-parser.js
is the result of modifying it with the following steps:
- Remove the anonymous function wrapper, including the return part;
- Find and move
class BuildInfo
from bottom to beginning and prefix withexport
; - Prefix
export
tofunction peg$parse(input, options)
.
The file ftl-core.ts
contains core classes representing different statements and expressions at run time. Almost all of them extend from the base functional class Fn
with apply(...)
. The most important ones are TupleFn
for functional tuple (t<sub>0</sub>, t<sub>1</sub>, ...)
, PipeFn
for operator ->
, and Tuple
representing value tuple for computation result of TupleFn
.
The builder ftl-builder.ts
takes parsed tokens from the parser and generate language elements in form of classes from ftl-core
. In the end, functions in a hierarchy are generated in memory, with which computation can be performed.
Run script npm run build
to make ftl
runnable.
All unit test cases are in src/ftl/test
. A unit test script is provided and runnable as:
npm run ftl-unit-test
The result will show all test files with the number of test cases in each file in the parentheses next to the file name and correspondingly each test result with true
or false
. If there is any failure with result as false
, it will show Failed testing [file name] with error ...
in the end of each test.
If all tests are passed, it will show "All tests Passed!
" in the end.
You can write your own program with FTL
anywhere and run it with ftl-runner.ts
as:
node [path/]ftl-runner.js [path/]ftl-code-file.ftl
For more information on how to lay out the structure of your program, see here.