[erlang-questions] some language changes

Christian S <>
Tue May 22 14:08:05 CEST 2007


On 5/22/07, Tony Finch <> wrote:
> On Mon, 21 May 2007, Joe Armstrong wrote:
> > 2. Hashmaps (aka associative arrays)
> How would this be different from ets?

Is this item the records-that-you-can-query-the-fields-of ? Replacing
our current compile time macro records?

A tiny though about records. Would this be too over engineered or heavy:

Often when one deal with records, one deal with more than one records
of the same kind. Imagine then that instead of adding better records
to the language, we add  a table type (or just hide it behind tagged
tuples, the interesting part is that it, the table, is reflective).

Having a table type one can begin adding higher level features to it.
Such as indexing two ways. Imagine a protocol where you have numeric
codes but you want to use atoms in your code. You have a mapping like:
[{ok, 0},
 {error, 1},
 {foo_reply, 2},
 ...,
 {baz_reply, 2324}]

It is common that when you encode protocol messages you have the atom
names, and want the numeric code, and the opposite when decoding
messages. This magic table type of ours can then support indexing for
faster lookup of either numeric to atoms or atoms to numeric. Lookup
could be made quite pretty with list comprehensions, looking similar
to a list of tuples:

<<Code:16/integer, Data/binary>> = Msg,
[MsgType] = [Name || ?{atom=Name, numeric=Code} <- Table],
Client ! decode(MsgType, Data),

The question mark being some syntax for matching a table. The
efficiency of the code depends on if the programmer has added the
following or not when constructing the table:

Table1 = tables:constraint(Table,
                                                   [{unique_index,
atom}, {unique_index, numeric}])

It would be a bit more heavy weight than the typical gen_server emacs
skeleton's state-record. But I think it can be afforded.

It would be natural for mnesia queries to be returned as a table
object. Various goodies that QLC do can be moved into properties of
the table object, and ordinary LCs can be made aware of tables to take
advantage of any indexing maintained by them.

A code switch modification of a table would be as simple as

Table1 = [?{apple=A, banana=bend(B), coconut=C} || ?{a=A, b=B, c=C} <- Table]

I begin to ask myself if the QLC stuff deserves more attention and
first-class citizenship. I also ask myself if this is the stuff better
suited for a programming language for stored procedures in an rdbm,
than a language for telecom and 3d modelling software.



More information about the erlang-questions mailing list