[erlang-questions] If you are homesick for object.selector

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Jan 24 13:39:29 CET 2013

On Jan 24, 2013, at 3:37 AM, Loïc Hoguin <essen@REDACTED> wrote:

> Character.current_weapon.ability.points_req

I think this is the major reason. It allows you to "chain" access to deep data. Note that this is a "projection" operation. You project out an element from the pair. The other solution, which is more Erlang-idiomatic is to match on the object and decode needed fields. But this solution is problematic when you need to access deep object data.

What you really need is composition of lenses, and a neat syntax for doing so. That is a composable access language for obtaining data deep in structures. The usual chaining projection does *not* work in Erlang because you don't know the type of the object at compile time, unless you have the record name to help you. For that to work, you need frames, or something which works the same.

On the other hand, when people access deep data like that, I often become concerned. Why is data not readily available to them but has to be dug up from far below the depths of a structure? Is this the right representation? There is overhead in following pointers and you can't always cache access over function boundaries.

Jesper Louis Andersen
  Erlang Solutions Ltd., Copenhagen

More information about the erlang-questions mailing list