(Updated Fri 2024-03-01)

Modularity in Fexl

Modularity is the ability to share code across multiple programs. To illustrate how this works, I'll start with an example. Let's say you're writing some code related to the old Flintstones cartoon. You can start by putting everything in one file:

try_1.fxl:

\\fred=(say "I am Fred.")
\\wilma=(say "I am Wilma.")
\\barney=(say "I am Barney.")
\\betty=(say "I am Betty.")

say "Meet the Flintstones."
fred
wilma
barney
betty

If you run that program, you see:

$ fexl try_1.fxl
Meet the Flintstones.
I am Fred.
I am Wilma.
I am Barney.
I am Betty.

So far so good, but what if you want to write another program that uses some of those same functions? Of course, you could simply copy the definitions you like into your new program, like this:

try_2.fxl:

\\fred=(say "I am Fred.")
\\wilma=(say "I am Wilma.")

say "Hello from Wilma and Fred."
wilma
fred

That's not an ideal solution, because you'd like to have your functions in a single library where you can maintain them in one place. Most functions will be a lot more complex than the ones in this example, and copying them everywhere will get ugly fast.

Instead, you can move the definitions into a separate library file, like this:

flintstones.fxl:

\\fred=(say "I am Fred.")
\\wilma=(say "I am Wilma.")
\\barney=(say "I am Barney.")
\\betty=(say "I am Betty.")

def "fred" fred;
def "wilma" wilma;
def "barney" barney;
def "betty" betty;
void

Then you can rewrite the first program like this:

try_1.fxl:

\cx_flintstones=(value std; use "flintstones.fxl")

value
(
:: cx_flintstones;
std
)
\;

say "Meet the Flintstones."
fred
wilma
barney
betty