[m-users.] Announcement (aggregates module) + questions (window functions)

Mark Clements <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <GV3P280MB000112C6DBF14A24B40FC09AF0F39@GV3P280MB0001.SWEP280.PROD.OUTLOOK.COM>
As an announcement, I have drafted a Mercury module for aggregates: see https://github.com/mclements/mercury-aggregates . This includes bag and set semantics for count, min, max, sum, avg, geom_mean, var, median and quantile.

As an extension, I have tried to implement window functions (https://en.wikipedia.org/wiki/Window_function_(SQL)) in Mercury: see https://github.com/mclements/mercury-aggregates/blob/main/test_window.m for an example. First, has anyone previously worked with window functions in Mercury? Second, is the syntax that I have used sensible (see code snippet below)? Here, bag_cum_sum and bag_row_number are functions that return a predicate, which is concise, but perhaps not obvious.

%% patient and visit are nondet predicates
main(!IO) :-
    print_line("{Id, RowNumber, Date, Score, CumScore}", !IO),
    aggregate((pred({Id,RowNumber,Datei,Scorei,CumScorei}::out) is nondet :-
                   patient(Id,_),
                   Combined = (pred(Date::out,Score::out) is nondet :- visit(Id,Date,Score)),
                   Combined(Datei,Scorei),
                   bag_cum_sum(Combined)(Datei,CumScorei),
                   Dates = (pred(Date::out) is nondet :- Combined(Date,_)),
                   bag_row_number(Dates)(Datei,RowNumber)),
              print_line,
              !IO).

Third, I have sought to stay with nondet predicates, with the implementation internally using lists -- is there a better approach?

Sincerely, Mark.


När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<https://ki.se/medarbetare/integritetsskyddspolicy>.


Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<https://ki.se/en/staff/data-protection-policy>.
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.