The Bash progamming language mixes Normal order evaluation (sometimes called "lazy" evaluation) and applicative order evaluation (sometimes called "eager" evaluation). Bash does not implement true lazy evalution since some arguments to a function or program are fully evaluated before the function is called. But arguments that are not variables or glob patterns are passed through to the program being called, and this allows for a very limited style of lazy functional programming.
Applicative order evaluation in Bash can be done with
command
substitution, such as the $(...)
or <(...)
syntax, as in the following examples:
# Use 'pkg-config' and 'find' to apply arguments # to the 'cc' program. cc -o my-app $(pkg-config --libs --cflags gtk+-x11-3.0 cairo pango) \ $(find src -type f -name '*.c') ; # Compare the output of 'find' run on 2 similar # directories to compare their tree structure. diff <(cd ./old && find . -type d) \ <(cd ./new && find . -type d) ;
One final example of applicative order evaluation in Bash: the
shell automatically expands certain symbols, like those containing
an asterisk *
as patterns
. So the *
symbol is a sort of shell built-in function that performs an
operation that evaluates before a command is run, returns a list of
all the files in the current working directory that match that
pattern, and passes this list as arguments to the command.
So I think it is clear that at least some degree of FP is possible in a UNIX Programming Environment due to the operational semantics of the Bourne shell family of programming languages. Of course I am ignoring other desireable properties of FP languages, such as purity, referential transparency, and strongly and/or statically type-checked programs, none of which exist in Bourne shell languages like Bash.