All functions with a Source of C, bool.fxl, math.fxl, list.fxl, hex.fxl, format.fxl, and main.fxl are automatically available to all Fexl programs. Others must be brought in explicitly, for example:
evaluate ( use_lib "date.fxl"; standard ) \; ...
Name | Description | Source |
---|---|---|
put | Print to standard output without a trailing newline.
put "Hello" put (* 3 4) put ["x = "(* 3 4)" y = "(+ 47 56)] |
C |
nl | Print a newline to standard output.
nl |
C |
say | Print to standard output with a trailing newline. | C |
fput | Print to a file handle without a trailing newline.
\fh=(fopen "result" "w") fput fh ["x = "(* 3 4)" y = "(+ 47 56)] |
C |
fnl | Print a newline to a file handle.
fnl fh |
C |
fsay | Print to a file handle with a trailing newline. | C |
fflush | Flush any pending output on a file handle.
fflush fh |
C |
+ | (+ x y) is the sum of x and y. | C |
- | (- x y) is x minus y. | C |
* | (* x y) is the product of x and y. | C |
/ | (/ x y) is x divided by y. | C |
^ | (^ x y) is x raised to the power of y. | C |
xor | (xor x y) is the bitwise exclusive-or of x and y, where x and y are cast as long integer values. | C |
round | (round x) is x rounded to the nearest integer. | C |
trunc | (trunc x) is the integer part of x, with the fractional part dropped. | C |
abs | (abs x) is the absolute value of x. | C |
sqrt | (sqrt x) is the square root of x. | C |
exp | (exp x) is e raised to the power of x. | C |
log | (log x) is the natural logarithm of x (base e). | C |
sin | (sin x) is the trigonometric sine of x. | C |
cos | (cos x) is the cosine of x. | C |
pi | pi is the numeric constant π. | C |
lt | (lt x y) is true if x is less than y. The arguments must be both numbers or both strings. | C |
le | (le x y) is true if x is less than or equal to y. | C |
eq | (eq x y) is true if x is equal to y. | C |
ne | (ne x y) is true if x is not equal to y. | C |
ge | (ge x y) is true if x is greater than or equal to y. | C |
gt | (gt x y) is true if x is greater than y. | C |
I | The identity function. (I x) = x. | C |
T | The boolean value true. (T x y) = x. | C |
F | The boolean value false. (F x y) = y. | C |
@ | The fixpoint function, used for looping/recursion.
It is defined to satisfy this equivalence:
(@ f) = (f (@ f)) |
C |
void | (void x) = void. This is the value returned by various functions when they cannot return a sensible result because their arguments are of the wrong type or otherwise erroneous. | C |
cons | (cons x xs) is the list consisting of the element x followed by the list xs. It is equivalent to the expression [x;xs]. | C |
null | null is the empty list. It is equivalent to the expression []. | C |
eval | (eval x f) = (f y), where y is the value of x. This is used to force the evaluation of x before proceeding. Ordinarily you can avoid the explicit use of eval by using the = syntax, because eval A (\x B) is equivalent to \x=A B . | C |
once | (once x) returns a value which defers the evaluation of x
until it's needed, and then it evaluates only once. Example:
seed_rand 0 \x=(once; put "(CALC)" rand) say x say xThe output is: (CALC)0.84018771715471 0.84018771715471If instead you had defined x as \x==(put "(CALC)" rand)) , then the output would be: (CALC)0.84018771715471 (CALC)0.394382926819093 |
C |
later | (later x) returns a value which defers the evaluation of x
until it's needed. Most of the time you won't need this,
because you can use the == syntax to defer evaluation.
For example:
\talk==(say "hello") talk talkThat says "hello" twice. However, in some rare cases you may want to evaluate an expression and have it return a value whose evaluation must be deferred until later. |
C |
is_defined | (is_defined x) is true if x is not void. Does not evaluate x. | C |
is_void | (is_void x) is true if the value of x is void. | C |
is_good | (is_good x) is true if the value of x is not void. | C |
is_bool | (is_bool x) is true if the value of x is boolean, either T or F. | C |
is_list | (is_list x) is true if the value of x is a list, either null or (cons A B) | C |
. | (. x y) is the concatenation of strings x and y. | C |
length | (length x) is the length of string x. | C |
slice | (slice str pos len) is the substring of str starting at position pos and proceeding for len characters. Positions start at zero. It clips as necessary to stay within the bounds of str. Returns void if pos or len is negative. | C |
search | (search haystack needle offset) searches the string haystack for the first occurrence of the string needle, starting at the position offset. Returns the position of the first occurrence of needle, or void if not found. | C |
str_num | (str_num x) converts the string x to a number, or void if the string is malformed. | C |
ord | (ord x) is the ordinal number of the first ASCII character of string x. | C |
chr | (chr x) is the ASCII character whose ordinal number is x. | C |
char_width | (char_width str pos) is the width of the UTF-8 character which starts at the given position within the string. | C |
dirname | (dirname x) strips the last component from file name x. See dirname(1). | C |
basename | (basename x) strips the directory from file name x. See basename(1). | C |
is_str | (is_str x) is true if x is a string. | C |
num_str | (num_str x) converts the number x to a string. | C |
is_num | (is_num x) is true if x is a number. | C |
is_tuple | (is_tuple x) is true if x is a tuple. For example:
(is_tuple {}) = T (is_tuple {"a"}) = T (is_tuple {"a" 3.2}) = T (is_tuple "a") = F |
C |
arity | (arity x) is the number of elements in tuple x.
For example:
(arity {}) = 0 (arity {"a"}) = 1 (arity {"a" 3.2}) = 2 (arity "a") = void |
C |
split_tuple | (split_tuple x A B) return A if tuple x is empty, otherwise
return (B left item), where left is the left part of the tuple,
and item is the last item in the tuple. For example:
split_tuple {} A B = A split_tuple {"a" "b" "c"} A B = (B {"a" "b"} "c") |
C |
join_tuple | (join_tuple xs x) forms a new tuple by combining tuple xs on
the left with item x on the right. For example:
join_tuple {"a" "b"} "c" = {"a" "b" "c"} |
C |
stdin | stdin is the standard input of the current process. | C |
stdout | stdout is the standard output of the current process. | C |
stderr | stderr is the standard error of the current process. | C |
fopen | (fopen path mode) opens a file and returns fh, where fh is the open file handle, or void on failure. | C |
fclose | (fclose fh) closes the file handle fh, and also sets fh to void so it doesn't core dump if you mistakenly try to close it again. | C |
fgetc | (fgetc fh) returns the next single byte from the file, or void if none. | C |
fget | (fget fh) returns the next UTF-8 character from the file, or void if none. | C |
remove | (remove path) remove path from the file system; return 0 if successful or -1 otherwise. | C |
is_newer | (is_newer file1 file2 returns true if file1 is newer than file2.
If either file is missing, it returns true, which makes the most sense for
caching operations.
It currently uses resolution only down to the whole second. I could potentially use nanosecond resolution, but that feature is not available on some older machines I use. |
C |
flock_ex | (flock_ex fh) obtains an exclusive lock on the file handle, blocking as long as necessary. | C |
flock_sh | (flock_sh fh) obtains a shared lock on the file handle, blocking as long as necessary. | C |
flock_un | (flock_un fh) releases any locks on the file handle. | C |
readlink | (readlink file) calls readlink on the file name (See man 2 readlink). | C |
die | die exits immediately with exit code 1. | C |
argv | (argv n) returns the command line argument at position n, starting at 0. Returns void if n is less than 0 or greater than or equal to argc (the argument count). | C |
seed_rand | (seed_rand x) seeds the pseudo-random number generator with a number x between 0 and 1. It multiplies x by RAND_MAX and calls srand(3). | C |
rand | rand returns a pseudo-random number in the range 0 through 1. It calls rand(3) and divides by RAND_MAX. Note that these numbers are not cryptographically strong. | C |
parse | (parse source label) parse the source, using the given label for any syntax error messages, and return the resulting form. The source may be a file handle, a string, or an istr (string iterator). | C |
parse_file | (parse_file name) parse the named file and return the resulting form. | C |
evaluate | (evaluate context exp) resolves the names in the expression using the given context and evaluates the result. | C |
resolve | (resolve context exp) resolves the names in the expression using the given context and returns the result for later evaluation. | C |
standard | standard refers to the the current context used in the enclosing call to evaluate or resolve. This is the function which maps each name in an expression (other than "standard" itself) to its definition. | C |
buf_new | buf_new returns a new empty character buffer. Example:
\buf=buf_new |
C |
buf_put | (buf_put buf str) appends the string to the buffer.
buf_put buf "abcdef" |
C |
buf_get | (buf_get buf) clear the buffer and return str, where str is
the current content of the buffer.
\str=(buf_get buf) |
C |
readstr | C | |
sgetc | C | |
sget | C | |
var_new | C | |
var_get | C | |
var_put | C | |
limit_time | C | |
limit_memory | C | |
limit_stack | C | |
and | (and x y) is the logical and (conjunction) of boolean values x and y. | bool.fxl |
not | (not x) is the logical negation of the boolean value x. | bool.fxl |
or | (or x y) is the logical or (disjunction) of boolean values x and y. | bool.fxl |
neg | (neg x) is the negative of number x. | math.fxl |
max | (max x y) is the maximum of numbers x and y. | math.fxl |
min | (min x y) is the minimum of numbers x and y. | math.fxl |
mod | (mod x n) is x modulo n.
It is defined as:
\mod=(\x\n - x; * n; trunc; / x n) |
math.fxl |
tau | tau is the numeric constant 2*π. | math.fxl |
round2 | (round2 x) is x rounded to two decimal places. | math.fxl |
append | (append x y) is the list consisting of the elements of list x followed by the elements of list y. | list.fxl |
each | list.fxl | |
map | list.fxl | |
map_good | list.fxl | |
filter | list.fxl | |
reverse | (reverse x) is the list consisting of the elements of list x in reverse order. | list.fxl |
append_all | list.fxl | |
g_sort | list.fxl | |
unique | list.fxl | |
sort | list.fxl | |
fold | list.fxl | |
first | list.fxl | |
skip | list.fxl | |
list_sum | list.fxl | |
list_length | list.fxl | |
is_null | list.fxl | |
range | list.fxl | |
list_at | list.fxl | |
list_combine | list.fxl | |
column | list.fxl | |
shift | list.fxl | |
match_column | list.fxl | |
stream_values | list.fxl | |
get_list | list.fxl | |
to_str | list.fxl | |
get_str | list.fxl | |
list_str | list.fxl | |
str_bytes | list.fxl | |
str_chars | list.fxl | |
str_map | list.fxl | |
join | list.fxl | |
join_path | list.fxl | |
split | list.fxl | |
file_bytes | list.fxl | |
hex_digit | hex.fxl | |
hex_byte | hex.fxl | |
hex_digit_to_dec | hex.fxl | |
map_hex_to_raw_bytes | hex.fxl | |
map_raw_bytes_to_hex | hex.fxl | |
xor_hex | hex.fxl | |
format_num | format.fxl | |
format_money | format.fxl | |
fexl_quote | format.fxl | |
uc | (uc x) is string x converted to all upper-case. | format.fxl |
lc | (lc x) is string x converted to all lower-case. | format.fxl |
fput_data | format.fxl | |
fput_list | format.fxl | |
put_data | format.fxl | |
put_list | format.fxl | |
define | main.fxl | |
if | (if x y) is y if the condition x is true, otherwise I
(the identity function). It is used to evaluate y for its side-effects
if the condition is true, otherwise do nothing and proceed. It is defined
as:
\if=(\x\y x y I) |
main.fxl |
with | main.fxl | |
TAB | main.fxl | |
NL | main.fxl | |
CR | main.fxl | |
LF | main.fxl | |
QU | main.fxl | |
check | main.fxl | |
use_file | main.fxl | |
use_lib | main.fxl | |
use | main.fxl | |
path_under | main.fxl | |
dir_base | main.fxl | |
dir_local | main.fxl | |
error | main.fxl | |
long_month_names | date.fxl | |
short_month_names | date.fxl | |
long_month_name | date.fxl | |
short_month_name | date.fxl | |
date_year | date.fxl | |
date_month | date.fxl | |
date_ymd | date.fxl | |
date_normal | date.fxl | |
date_quarter | date.fxl | |
month_ym | date.fxl | |
ym_month | date.fxl | |
ymd_date | date.fxl | |
month_before | date.fxl | |
month_after | date.fxl | |
ym_num_days | date.fxl | |
fill_day | date.fxl | |
day_after | date.fxl | |
date_end_prev_month | date.fxl | |
date_end_prev_quarter | date.fxl | |
date_end_prev_year | date.fxl | |
same_quarter | date.fxl | |
count_days | date.fxl | |
day_of_week | date.fxl | |
add_days | date.fxl | |
add_year | date.fxl | |
quote_ch | html.fxl | |
quote | html.fxl | |
colgroup | html.fxl | |
_tag | html.fxl | |
tag | html.fxl | |
tr | html.fxl | |
put_quote_data | html.fxl | |
put_quote_list | html.fxl | |
encode_percent | html.fxl | |
make_url | html.fxl | |
read_csv_chars | read_csv.fxl | |
read_csv_file | read_csv.fxl | |
read_ssv_chars | read_ssv.fxl | |
read_ssv_file | read_ssv.fxl |