This version is much less segmented than the original but it is still not a single execution stream which I think is what you were asking for, @c4augustus. This new version supports all the ways to run this using escript, erl, or erl -noshell. To allow it only to run through escript means these two lines could be removed:
main(A) when is_atom(A) -> main(atom_to_list(A));
main(F) when is_float(F) -> isBadNum(F), main();
main() without parameters simply reads the countdown: input from the console and calls main(_) with the result. The body of main() could be moved to line 27, thus keeping all the processing inside of main(_). We would still need main() -> main(""), however, and I like it this way better, anyway, because it clearly says "main with no parameters takes countdown input."
The lack of mutability and traditional looping statements makes it very challenging to do what you asked. While it may be possible with lambdas, I hardly think it's worth it and it seems counter to tacit Erlang development.
Anyway, take a look and let me know what you think.
This version is much less segmented than the original but it is still not a single execution stream which I think is what you were asking for, @c4augustus. This new version supports all the ways to run this using
escript
,erl
, orerl -noshell
. To allow it only to run throughescript
means these two lines could be removed:main()
without parameters simply reads thecountdown:
input from the console and callsmain(_)
with the result. The body ofmain()
could be moved to line 27, thus keeping all the processing inside ofmain(_)
. We would still needmain() -> main("")
, however, and I like it this way better, anyway, because it clearly says "main with no parameters takes countdown input."The lack of mutability and traditional looping statements makes it very challenging to do what you asked. While it may be possible with lambdas, I hardly think it's worth it and it seems counter to tacit Erlang development.
Anyway, take a look and let me know what you think.