Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.1
    • Component/s: None
    • Labels:
      None

      Description

      There is no common API to access the dynamic variables.

      -record(dyndata,

      {dynvars, % dynamic variables proto % dynamic data specific to protocole (#http_dyndata for HTTP) }

      ).

      The dynamic variables are currently stored using a key-value lists, but some additional test are required before accessing it (because instead of being a list they may also be the atom 'undefined').

      The rationale for specifying an API is that they are being used in different parts of the codebase, and dynamic variables are also exposed to the end user as one of the argument to callback functions.

      One option will be to continue to use key-val lists, (documenting that), and make changes to ensure that they always are valid key-value list (so instead of 'undefined' use an empty list). This way, the clients can use the proplists module, or the lists:key* functions.

      Other option is to define our own ADT for dynamic variables. This could have other benefices, like ensuring that all the keys are atoms, provide a simpler interface, and allowing us to switch the backend implementation if that is necessary (proplists,dicts, gb_trees,etc)

      The api could look something like:

      @spec make() -> DynVars()
      @doc new,empty
      make() ->

      %% @spec lookup(DynVar(),Key::atom()) ->

      {ok,Value:term()}

      | false
      lookup(DynVars,Key)->

      %% @doc same as lookup/2, only that if the key isn't present, the default
      %% value is returned instead of returning false.
      lookup(DynVars,Key,Default)

      %% @spec set(DynVars(),Key:atom(),Value::term) -> DynVars()
      set(DynVars,Key,Value) ->

      %% @doc return all dynamic variables as a list of

      {Key,Value}

      tuples
      entries(DynVars) ->

      %% @spec map(Fun,Key::atom(),Default::term(),DynVars()) -> DynVars
      %% @type Fun : term() -> term()
      %% @doc If the value associated to key Key is PreviousVal, then it is replaced with
      %% the result of applying function Fun(PreviousVal).
      %% If there is no such previous value, Key is assosiated with the result of calling Fun(Default).
      %% (this is mostly useful to maintain counters (default = 0) or accumulate values (default = [])
      map(Fun,Key,Default,DynVars) ->

      1. ts_dynvars.erl
        2 kB
        Pablo Polvorin
      2. ts_test_dynvars_api.erl
        2 kB
        Pablo Polvorin

        Activity

        Hide
        Pablo Polvorin
        added a comment -

        Dynamic Variables ADT

        Show
        Pablo Polvorin
        added a comment - Dynamic Variables ADT
        Pablo Polvorin
        made changes -
        Field Original Value New Value
        Attachment ts_dynvars.erl [ 12766 ]
        Attachment ts_test_dynvars_api.erl [ 12767 ]
        Hide
        Nicolas Niclausse
        added a comment -

        It's a good idea.

        I add the bug for the 1.3.1 release, since 1.3.0 should be released as soon as the doc is updated.

        Show
        Nicolas Niclausse
        added a comment - It's a good idea. I add the bug for the 1.3.1 release, since 1.3.0 should be released as soon as the doc is updated.
        Nicolas Niclausse
        made changes -
        Fix Version/s 1.3.1 [ 10223 ]
        Nicolas Niclausse
        08/10/08 10:16
        View full commit
        don't use lists:keystore (only for R12B) rename make -> new (TSUN-81). SVN Revision: 904
        Nicolas Niclausse
        08/10/08 10:16
        View full commit
        don't use lists:keystore (only for R12B) rename make -> new (TSUN-81). SVN Revision: 904
        Hide
        Nicolas Niclausse
        added a comment -

        implemented in rev 904

        Show
        Nicolas Niclausse
        added a comment - implemented in rev 904
        Nicolas Niclausse
        made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Christophe Romain
        made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mickaël Rémond
        made changes -
        Workflow jira [ 58965 ] Development v4 [ 85355 ]

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              5 years, 10 weeks, 3 days ago

              Issue deployment