[erlang-questions] Here's hoping we get frames or structs in 2009!

mats cronqvist <>
Mon Jan 19 10:10:44 CET 2009


Robert Virding <> writes:

> Something like this could be done for a struct/frame but have a special data
> type. In that case it would look like a record but there the "name" field
> would be a descriptor showing which fields there are and where in the "tuple"
> they are. There would be no need to keep anything in an ets table.

  i've been playing around with a data structure like this. "Anonymous
  records", tuples where the first element is a fun describing the
  fields. E.g.

  {F,"A","B"}

  where F = fun(a)->2;
               (b)->3;
               (1)->a;
               (2)->b
            end.

  Then this;

  AR#.a

would be 

  element((element(1,AR))(a),AR) == "A"

  and 

f(AR#{a="A"}) ->

would be

f(AR) when element((element(1,AR))(a),AR)=="A" ->

  etc.

  mats



More information about the erlang-questions mailing list