Example bash script for generating math monadics over various modes
jpl
jpl.algol68@gmail.com
Sat May 2 19:03:01 GMT 2026
Discussion from last nights BBB group meeting proposed that we may wish to
create a large number of monadic operators to simplify writing/maintaining
code.
For example, with these monads "Sin(x)" could be used for real x, long real
x, or even long long real x (As opposed to using "sin", "long_sin", and
"long_long_sin" depending on the arguments mode.
I have put together an example bash script that generates algol 68 code.
It is not a complete version but shows the basic idea to avoid the
combinatoric pains.
All comments, critique is welcomed on this. In the meantime, complete the
list of desired monads and desired modes.
Cheers,
James
Example output:
pub op = Sqrt(real x) real: sqrt(x);
pub op = Sqrt(long real x) long real: long_sqrt(x);
pub op = Sqrt(long long real x) long long real: long_long_sqrt(x);
pub op = Exp(real x) real: exp(x);
pub op = Exp(long real x) long real: long_exp(x);
pub op = Exp(long long real x) long long real: long_long_exp(x);
Here is the bash script:
#!/bin/bash
# generates lines of Algol68 code defining monadic operators
# array of monadic operators we wish to define
declare -a op=("Sqrt" "Exp" "Ln" "Cos" "Arccos" "Sin" "ArcSin" "Tan"
"Arctan")
# array to modes of interest and associated prefixes to assigne to
procedure name
declare -a mode=("real" "long real" "long long real")
declare -a alt=("" "long_" "long_long_")
num_op=${#op[@]}
num_mode=${#mode[@]}
for (( i=0; i<${num_op}; i++ ));
do
OP=${op[i]}
PROC=${OP,} # change first letter of OP variable to lowercase
for (( j=0; j<${num_mode}; j++ ));
do
MODE=${mode[j]}
ALT=${alt[j]}
echo "pub op = $OP($MODE x) $MODE: $ALT$PROC(x);"
done
echo
done
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20260502/4b08c760/attachment.htm>
More information about the Algol68
mailing list