Module egtm_util

EGTM Utilities.


EGTM Utilities.

Function Index

foreach/2Foreach implementation based on egtm:order() and egtm:get().
foreach/3Equivalent to foreach(Gvn, Subs).
gforeach/0Equivalent to gforeach(PrintAllGvnsFunction).
gforeach/1Global Variable Name Foreach.
lock/2Equivalent to lock(Gvn, Subs, Fun).
lock/3Run a function Fun within a lock-block on Gvn global with Subs subscripts.
longstring_get/2Equivalent to longstring_set(Gvn, Subs, Text).
longstring_kill/2Equivalent to longstring_set(Gvn, Subs, []).
longstring_set/3Equivalent to longstring_set(Gvn, Subs, Text, 4000).
longstring_set/4Longstring get/set support.
set_term/1Sets terminal characteristics.
stringify/1Convert any datatype to string.
transaction/1Transaction processing (TP) support.

Function Details


foreach(Gvn::global_name(), Subs::subscripts()) -> nomatch | {ok, AccumulatedData::list()}

Foreach implementation based on egtm:order() and egtm:get(). Gvn is a name of MUMPS global array. Subs is a list of keys (subscripts) [S1,...,SN] so that S(N+1) will be used to `egtm:order() over. Fun argument is function of arity 2 (Gvn, Subs) or arity 3 (Gvn, Subs, ResultAccumulator). If the Fun argument is not specified, all the records will be written on standard output via io:format().

  egtm_util:foreach ("^Foo", [1,2,3], fun (G, S) ->
    io:format ("~p ~p -> ~p", [G, S, egtm:get (G, S)]) end). equivalent of MUMPS code similar to this:
  N X S X="" F  S X=$O(^Foo(1,2,3,X)) Q:X=""  D
  . W $NA(^(X)),"=",$G(^(X)),!


foreach(Gvn::global_name(), Subs::subscripts(), Fun::function()) -> nomatch | {ok, AccumulatedData::list()}

Equivalent to foreach(Gvn, Subs).


gforeach() -> any()

Equivalent to gforeach(PrintAllGvnsFunction).


gforeach(Fun) -> any()

Global Variable Name Foreach. Uses special case of MUMPS $Order (GT.M-specific trick!) to iterate over all global variables available.

Fun is function of arity one or two. First argument passed to Fun is the name of global variable and the second (optional) is result accumulator variable.

When used with the Fun of arity of one, the accumulator is automatically collected as the list of all the results of each Fun call.

  erl> egtm_util:gforeach ().
  erl> egtm_util:gforeach (fun (G) -> G end).
  erl> egtm_util:gforeach (fun (G) -> egtm:data (G) end).
  erl> egtm_util:gforeach (fun (G, Res) -> {ok, R} = egtm_util:foreach (G, []), Res end).
  erl> egtm_util:gforeach (fun (G, Res) ->
         {ok, R} = egtm_util:foreach (G, [],
           fun (G, S, A) -> [{S,egtm:get (G, S)}|A] end),
         [{G,R}|Res] end).


lock(Gvn::global_name(), Fun::function()) -> Result::any()

Equivalent to lock(Gvn, Subs, Fun).


lock(Gvn::global_name(), Subs::subscripts(), Fun::function()) -> Result::any()

Run a function Fun within a lock-block on Gvn global with Subs subscripts.


longstring_get(Gvn::global_name(), Subs::subscripts()) -> Result::string()

Equivalent to longstring_set(Gvn, Subs, Text).


longstring_kill(Gvn::global_name(), Subs::subscripts()) -> {ok, Result::any()} | {error, Reason::any()}

Equivalent to longstring_set(Gvn, Subs, []).


longstring_set(Gvn::global_name(), Subs::subscripts(), Text::string()) -> {ok, Result::any()} | {error, Reason::any()}

Equivalent to longstring_set(Gvn, Subs, Text, 4000).


longstring_set(Gvn::global_name(), Subs::subscripts(), Text::string(), BlockSize::integer()) -> {ok, Result::any()} | {error, Reason::any()}

Longstring get/set support. longstring_set and longstring_get usually operates on strings with sizes larger than maximal GT.M string (1MB) limit. The mechanism is based on cutting strings into chunks of (optionally) specified length BlockSize and putting them into subindex of Subs subscripts in Gvn global.

BlockSize cannot be less than 1 and if specified incorrectly or completely missing, it is expected to be 4000 by default.

Example (BlockSize=5):
  erl> egtm_util:longstring_set ("^Foo", ["a","b"], "hello world from erlang and gt.m!", 5).
  erl> egtm_util:longstring_get ("^Foo", ["a","b"]).
  "hello world from erlang and gt.m!"
  erl> egtm_util:foreach ("^Foo", ["a","b"]).
  ^Foo["a","b","2"]=" worl"
  ^Foo["a","b","3"]="d fro"
  ^Foo["a","b","4"]="m erl"
  ^Foo["a","b","5"]="ang a"
  ^Foo["a","b","6"]="nd gt"


set_term(Flag::nocenable) -> ok

Sets terminal characteristics. At the moment, only NOCENABLE is currently supported. (= U $P:NOCENABLE).


stringify(Data::any()) -> Result::string()

Convert any datatype to string.


transaction(Fun::function()) -> {ok, commit | rollback, Status::any()}

Transaction processing (TP) support. The only parameter of Fun is function that is to be run within a transaction block.

  case transaction (fun () ->
      egtm:lock (Gvn, Subs),
      egtm:kill (Gvn, Subs),
      egtm:set (Gvn, Subs, Value),
      egtm:unlock (Gvn, Subs)
    end) of
    {ok, commit, Res} -> {ok, Res};
    Whatever          -> {error, Whatever}
  end a Erlang equivalent of MUMPS code similar to (if Gvn="^Foo", Subs=[1,2,3] and Value="abc"):
     TS  L +^Foo(1,2,3) K ^Foo(1,2,3) S ^Foo(1,2,3)="abc" L -^Foo(1,2,3) TC

Generated by EDoc, Aug 19 2012, 02:27:27.