Module Rascl.Dict


module Dict: sig .. end
This module implements the fundamental data structure of RASCL: the dictionary. This is a key-value structure whose keys are strings and whose values may be strings, lists, or dictionaries. Dictionaries have no fixed size, and their elements are mutable.

type t 
The type of dictionaries.

type data =
| S of string
| L of string list
| D of t
The type for dictionary values.
val create : ?locked:bool -> unit -> t
Dict.create ?locked () creates a new, empty dictionary. The locked parameter indicates whether new nested dictionaries may be added. Its default value is false, i.e. new nested dictionaries are allowed.
val get : ?prefix:string list -> string -> t -> data
Dict.get ?prefix key dictionary retrieves the value associated with key in dictionary, raising Not_found if the key is not present. When retrieving an item from a subdictionary, ?prefix may be used to specify the subdictionary.
val set : ?prefix:string list -> string -> data -> t -> unit
Dict.set ?prefix key value dictionary sets the value for key in dictionary to value. When setting a value in a subdictionary, ?prefix may be used to specify the subdictionary.
val get_string : ?prefix:string list -> string -> t -> string
Dict.get_string ?prefix key dictionary retrieves the value associated with key as a string. The stored value should match the pattern S s, otherwise an exception will be raised. ?prefix behaves as in Dict.get.
val get_dict : ?prefix:string list -> string -> t -> t
Dict.get_dict ?prefix key dictionary retrieves the value associated with key as a dictionary. The stored value should match the pattern D d, otherwise an exception will be raised. ?prefix behaves as in Dict.get.
val get_list : ?prefix:string list -> string -> t -> string list
Dict.get_list ?prefix key dictionary retrieves the value associated with key as a list. The stored value should match the pattern L l, otherwise an exception will be raised. ?prefix behaves as in Dict.get.
val set_string : ?prefix:string list -> string -> string -> t -> unit
Dict.set_string ?prefix key value dictionary sets the value for key in dictionary to S value. ?prefix behaves as in Dict.set.
val set_list : ?prefix:string list -> string -> string list -> t -> unit
Dict.set_list ?prefix key value dictionary sets the value for key in dictionary to L value. ?prefix behaves as in Dict.set.
val set_dict : ?prefix:string list -> string -> t -> t -> unit
Dict.set_dict ?prefix key value dictionary sets the value for key in dictionary to D value. ?prefix behaves as in Dict.set.
val copy : t -> t
Dict.copy dictionary returns a new dictionary whose elements are copies of those in the original dictionary. This is a deep-copy operation.

Iterators and filters

The following functions are similar to the iter, map, and filter functions associated with other data structures. Note, however, that there is no automatic recursion into subdictionaries. If you require such recursion, you must supply an appropriate recursive function. For example:

      let rec f key value =
        match value with
        | S s -> ....
        | L l -> ....
        | D subdict -> Dict.iter f subdict
  

val iter : (string -> data -> unit) -> t -> unit
Dict.iter f dictionary applies f in turn to each element of dictionary.
val map : (string -> data -> data) ->
t -> t
Dict.map f dictionary applies f in turn to each element of dictionary, returning a new dictionary whose values are the results of f applied to each value in the original dictionary.
val filter : (string -> data -> bool) -> t -> t
Dict.filter f dictionary applies f in turn to each element of dictionary, returning a new dictionary whose elements are copies of all those for which f returned true.
val do_in : string list -> (t -> unit) list -> t -> unit
Dict.do_in context ff dictionary executes in turn a list of functions, each of which takes a dictionary as its argument. context specifies the subdictionary to which ff should be applied; if context is an empty list, ff are applied to dictionary.
val get_from : string list -> string list -> t -> (string * data) list
Dict.get_from context keys dictionary retrieves an association list of keys and values from dictionary, or from a subdictionary identified by context.
val set_in : string list -> (string * data) list -> t -> unit
Dict.set_in context elements dictionary sets the key-value pairs specified by elements in dictionary, or in a subdictionary identified by context.
module Unsafe: sig .. end
The contents of this module are subject to change without notice.