Function EXpression Language
Fexl Summary
Here are some examples illustrating the major features of Fexl™.
Hello world
print "Hello world"
A couple of basic list functions
The append function appends two lists x and y.
\append=(\x\y x y \h\t item h; append t y)
For example:
: append
(item 1; item 2; item 3; end)
(item 4; item 5; end)
= (item 1; item 2; item 3; item 4; item 5; end)
The reverse function reverses a list x. Notice how it uses an auxiliary function f which takes in the list x along with an accumulator y which is initially null. It then "stacks up" the elements of x onto the accumulator y, returning the final value of y as a result.
\reverse=(
\accumulate=
(\list\stack list stack
\head\tail accumulate tail (item head stack))
\reverse=(\list accumulate list end)
)
For example:
: reverse (item 1; item 2; item 3; item 4; end)
= (item 4; item 3; item 2; item 1; end)
Multiple return values
This sort of thing is very easy in a pure function language:
divide numerator denominator \quotient\remainder ...
Of course, it's not really multiple return values. Instead, the divide function takes a function as its third input, and passes the quotient and remainder into that function.
Concurrency
Concurrency can be modeled as static functions operating on simple trees. I'll describe the concept here when I make some time.
Modularity
Fexl can easily parse another Fexl program, get a list of any undefined symbols in that program, and supply any definitions it likes. This simple concept is an extremely powerful basis for modular system construction. The sky's the limit. You could even write a Fexl program to look up some function definitions out on the internet somewhere. Of course you would run these in an appropriate "sandbox" for security.
Security
You can give Fexl the full power of the machine if you like. But you can also easily create completely sealed environments for running application code safely. This is especially good for web applications.
Completely reflective & self-referential language
You can start simple with a basic Fexl interpreter written in C, Perl, Python, Ruby, Lisp, or whatever. But once you have a Fexl interpreter of any kind, you can do all sorts of mind-bending things. You can, for example, write a Fexl interpreter entirely in Fexl.
Good for application-specific languages
Don't like the syntax? Need an application-specific language? Then just write your own parser to map your own programming language into the Fexl engine. It's not as bad as it sounds. Use the Fexl parser as a starting point so you don't have to write it from scratch.
Good for embedded applications
The Fexl engine is compact and suitable for embedded applications.
"Here-is" documents
Fexl makes it very easy to include arbitrary strings within a program. Normally you just use double-quotes to delineate a string, for example "hello". However, if you want to include double-quotes within the string itself you have to do something different because otherwise Fexl cannot know where the end of the string is.
The solution is simple. Put a ~ (tilde) in front of the first quote mark, and another ~ after the last quote mark. For example:
~"You can use " and ~ with no problem."~
Now if you're sharp, you might be wondering how to put "~ inside the string itself! Simple: add another layer of tildes around it:
~~"You can use " and ~ and "~ with no problem."~~
If you need to put "~~ inside the string, add another layer of tildes again. You can use as many layers as you want, as long as the number of tildes before and after the first and last quote match up. With a long string you might even use extra layers of tildes beyond necessity:
\program =
~~~~"
# This is a small Fexl program inside a string.
\n = 3
\n:squared = (* n n)
print "The value is "; print n:squared
"~~~~
We only needed one tilde there, but the four tildes help set off the string nicely and give us some latitude in case we decide to use a tilde quotation inside the embedded program itself.