[erlang-questions] Reassigning variables
Gaspar Chilingarov
nm@REDACTED
Wed Mar 18 13:38:19 CET 2009
I'm totally agree with you, Richard!
Even in complex project I had practically no need of reassignment.
1. There is a nested calls which is possible to format nicely
f1(
f2(
f3( Args )
)
);
2. If you need complex and very flexible solution - implement simple
stack machine - you pass to the interpreter 2 lists - list of functions
to be called, the initial stack (well, I've beed passing there also
application/process global state variable)
As a single processing function result you get:
{continue, NewStack, NewState} - continue applying next command in a
command list
{error, ErrorMsg, NewState} - stop processing and throw a message (we
got an error)
{ok, Result, NewState} - stop processing and return some value to
calling function.
It's rather easy to write/debug such kind of interpreter and then
describe ALL necessary logic in that interpreter.
(We had an interpreter for web-based application - form
generation/validation/submit processing and etc).
We also described all the periodic tasks occurring in the system as a
such command list (btw closures+mnesia rule in term of keeping
application state intact for further processing).
Well :) It took 2 software revisions to get there :) Using
positional/named registers was too hard and messing all the things up.
Tip: for easier processing attach to variables in stack their type -
which will make finding errors in your processing chains easier.
--
Gaspar Chilingarov
tel +37493 419763 (mobile - leave voice mail message)
icq 63174784
skype://gasparch
e mailto:nm@REDACTED mailto:gasparch@REDACTED
w http://gasparchilingarov.com/
More information about the erlang-questions
mailing list