2 Diving In
2.4.1 Variables in the REPL
Variables in LFE don't have the same syntactical limitations that vanilla Erlang has. Let's take a look at some examples in the REPL:
Your variable does not have to start with a capital letter and not only can it contain special characters, it can entirely consist of them! We don't recommend this, however ;-)
Furthermore, LFE also does not share with Erlang the characteristic of not being able to change a variable once you've set it's value. In the REPL you can do this without issue:
In previous sections we've set variables and worked with those variables in the REPL (saving us some typing), so this should all seem a bit familiar.
As such, this should be fairly intuitive clear at this point:
Unlike Erlang, the LFE REPL doesn't have the
("show bound variables" and "flush bound variables" respectively).
2.4.2 Variables in LFE Modules
Unlike Lisp, LFE doesn't support global variables, so (unless you create some dirty hacks!) you won't be doing things like this in your modules:
(Not to mention that LFE doesn't even define
As such, you shouldn't run into variables that are defined at the module-level, only inside actual functions.
2.4.2 Variables in Functions
There are all sorts of ways one might set a variable in an LFE function. The snippets below illustrate some of these, though for demonstration purposes, they are executed in the REPL.
Above we set two variables, and then withing the scope of the
display some values, one of which is computed from the variables.
In this example, we make use of
let*'s ability to use defined variables
in subsequent variables assignments. Tying this with regular
result in an error.
Here is an example of multiple-binding in LFE. We haven't covered patterns yet,
but we will -- and this example is making use of patterns to assign data from
the given record to the variables in the
Patterns may be used in several different LFE forms, each of which may do some varaible binding.