Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request library(aggregate) #603

Open
Jean-Luc-Picard-2021 opened this issue Oct 6, 2024 · 3 comments
Open

Feature request library(aggregate) #603

Jean-Luc-Picard-2021 opened this issue Oct 6, 2024 · 3 comments

Comments

@Jean-Luc-Picard-2021
Copy link

Jean-Luc-Picard-2021 commented Oct 6, 2024

Wanted to run Numbrix Puzzle. Banged my head here:

?- time(aggregate_all(count, (length(_L, 16), line(_L)), C)).
   throw(error(existence_error(procedure,aggregate_all/3),aggregate_all/3)).

I know that I can use countall/2 instead:

?- time(countall((length(_L, 16), line(_L)), C)).
% Time elapsed 0.163s, 1138078 Inferences, 6.989 MLips
   C = 552.

But the countall/2 looks a little limited to me. Its
not future proof. What if we want i.e. failure driven loop
summing or failure driven multiplication,

does this mean for every new aggregate there will
be a new predicate sumall/2, predall/2, etc... Not
sure whether this is a way ahead,

since library(aggregate) usually offers more. In
the world of aggregates there are equivalents of
aggregates to findall/3 and bagof/3 which can

reuse the same aggregates. So what the library
offers is only 2-3 predicates such as aggregate_all/3
and aggregate/3, plus a set of aggregates.

@infradig
Copy link
Contributor

infradig commented Oct 6, 2024

Try copying aggregate.pl over on your system. I won't include it in Trealla as it seems to be the sole work of Jan.

I couldn't access your numbrix attachment.

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Oct 6, 2024

Not sure whether you can run SWI-Prolog library(aggregate)
on your system. To realize failure driven versions of count, sum, etc..
it uses nb_setarg/3, which is an implementation specific feature

of SWI-Prolog. I don't find nb_setarg/3 listed here for Trealla:

https://github.com/trealla-prolog/trealla

So simply copying over aggregate.pl is possibly not an option.

BTW: Second try to upload Numbrix:

numbrix.p.log

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Oct 6, 2024

With nb_setarg/3 you can also easily program call_nth/2
in Prolog itself. Or even bootstrap another useful library,
which is library(solution_sequences).

I introduced nb_setarg/3 in the form of change_arg/3 in
Dogelog Player. It turned out a little nightmare implementing
it, especially garbage collection issues. But I used it to bootstrap

library(sequence) which has call_nth/2. So nb_setarg/3 is quite handy!
But it seems you have things like limit/2 and offset/2 already
implemented natively. So its maybe to late for this synergy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants