[erlang-questions] Dictionary strategy of last value wins
Tue Jun 24 04:51:31 CEST 2014
Mailer issues lost my first draft and resulted in the 2nd being only
addressed to Bob. Posting for the list and feedback.
On Jun 23, 2014, at 7:18 PM, Jay Nelson <> wrote:
> On Jun 22, 2014, at 11:16 AM, Bob Ippolito <> wrote:
>> If you do want to keep a full history of inserts, couldn't you use a dict(K, [V])? Sure, you'd have to write a few functions, since dict:append/3 doesn't have the desired semantics, but such functions are straightforward to write.
>> prepend(K, V, D) ->
>> dict:update(K, fun (Vs) -> [V | Vs] end, [V], D).
> It’s kind of funny that the imperative append is provided in our functional dict
> module. I guess it mirrors the thinking on the init list. This is a simple approach
> to keep versioned data for all keys.
> I rambled too much in my original post. My question was actually only about the
> initialization. I am trying to make an abstract dictionary for object-like handling
> of data, with translation between DB access and Application access. The seeds
> of the idea are at https://github.com/duomark/epode/tree/dict-types (I haven’t
> merged the latest code to master yet).
> As a library I wanted to provide a convenient initialization method with proplists
> as my guide, because initializing sets of objects with defaults and contextual
> overrides fits the model of push down contexts or environments better. I am
> curious if people initialize their dictionaries with imperatively constructed lists
> (with the most recent change at the end, relying on clobber semantics) or
> with push/pop contexts on top of default values.
> The recommended approach for maps is to merge a default map with the
> overrides (or I suppose a sequence of overrides and rule for proper merge
> ordering). Dictionaries appear to be an imperative approach that has been
> adapted to functional in a way that exhibits features of both approaches.
> I was conditioned with LISP to use proplists and environment contexts.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions