Module egtm_util

EGTM Utilities.

Description

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/2

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().

Example:
  egtm_util:foreach ("^Foo", [1,2,3], fun (G, S) ->
    io:format ("~p ~p -> ~p", [G, S, egtm:get (G, S)]) end).
...is 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/3

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

Equivalent to foreach(Gvn, Subs).

gforeach/0

gforeach() -> any()

Equivalent to gforeach(PrintAllGvnsFunction).

gforeach/1

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.

Examples:
  erl> egtm_util:gforeach ().
  ^%EUnit=[]
  ^ZFOO="1"
  ^ZTMR="1"
  {ok,["^%EUnit","^ZFOO","^ZTMR"]}
 
  erl> egtm_util:gforeach (fun (G) -> G end).
  {ok,["^%EUnit","^ZFOO","^ZTMR"]}
 
  erl> egtm_util:gforeach (fun (G) -> egtm:data (G) end).
  {ok,[10,1,11]}
 
  erl> egtm_util:gforeach (fun (G, Res) -> {ok, R} = egtm_util:foreach (G, []), Res end).
  ^%EUnit["perf"]=[]
  ^ZTMR["1"]="2"
  ^ZTMR["2"]="3"
  ^ZTMR["3"]="4"
  {ok,[]}
 
  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).
  {ok,[{"^ZTMR",[{["3"],"4"},{["2"],"3"},{["1"],"2"}]},
       {"^ZFOO",[]},
       {"^%EUnit",[{["perf"],[]}]}]}

lock/2

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

Equivalent to lock(Gvn, Subs, Fun).

lock/3

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/2

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

Equivalent to longstring_set(Gvn, Subs, Text).

longstring_kill/2

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

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

longstring_set/3

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/4

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).
  {ok,done}
 
  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","1"]="hello"
  ^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"
  ^Foo["a","b","7"]=".m!"

set_term/1

set_term(Flag::nocenable) -> ok

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

stringify/1

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

Convert any datatype to string.

transaction/1

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.

Example:
  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
...is 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.