BEAM implementation questions
Wed Jan 26 11:26:09 CET 2005
--- Dominic Williams <erlang-list@REDACTED>
> Thomas Lindgren wrote:
> > I'd like support for this, perhaps even moreso if
> > there was some language support for declaring
> > "constant data".
> I'm curious about why you'd want any specific
> What's wrong with a constant function, e.g.:
> pi() -> 3.1415.
> max_users() -> 50.
There's nothing _really_ wrong with functions
returning constant data, I just find it (a bit)
clearer to have a separate notation to say "this is a
data access, not a computation" and to indicate that I
want this data to be cached and shared somewhere. (In
some cases you instead want to hide that distinction,
Here's one case where it turns up: when I build a
lexer (lex.erl in jungerl), I dynamically generate the
lexing table and index into it when driving the lexer.
But it would be nicer to instead have a data structure
I could emit once and for all, and then index into it
with something like:
lextable[StateName, Char] (forgive the syntax :-)
with lextable/2 thus being a constant 2D array, not a
function. Saving the generated table as a loadable
module would also be quite useful.
The same issue turns up for yecc, incidentally, which
generates a huge swathe of code in order to implement
what amounts to a table. Cf. erl_parse.erl.
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
More information about the erlang-questions