[m-users.] Useful predicates for loops of IO actions
Volker Wysk
post at volker-wysk.de
Wed Dec 22 03:34:24 AEDT 2021
Am Dienstag, dem 21.12.2021 um 16:28 +0000 schrieb Sean Charles (emacstheviking):
> Hi Volker, I use code like this all the time for !IO and folding,
> run_info(Options, !IO) :-
> aio.format("@cy:Environment variables:@-\n", [], !IO),
>
>
> list.foldl(
> (pred(S::in, !.IO::di, !:IO::uo) is det :-
> get_env_str(S, "", ENV, !IO),
> aio.format("@yl:%15s:@- %s\n",
> [s(S), s(ENV)],
> !IO)
> ), ["FELT_INST", "FELT_DOCS", "FELT_PAGER", "FELT_EDITOR",
> "FELT_LEX", "FELT_AST", "FELT_TRN"],
> !IO),
>
>
> aio.format("@cy:Command line options:@-\n", [], !IO),
>
>
> list.foldl(
> (pred(K::in, !.IO::di, !:IO::uo) is det :-
> map.lookup(Options, K, V),
> aio.format("@yl:%15s:@- %s\n",
> [s(string(K)), s(string(V))],
> !IO)
> ),
> map.sorted_keys(Options),
> !IO).
>
> Like Zoltan says, the code practically writes itself, I’ve not found the need to for threading !IO through anything to be honest!
But that's exactly what you're doing in the example above, by using foldl.
Cheers, Volker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20211221/453653a7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20211221/453653a7/attachment.sig>
More information about the users
mailing list