ciao-lang/ciao

Feature request predicate divmod/4

Jean-Luc-Picard-2021 opened this issue · 3 comments

Its quite customary that Prolog systems nowadays
have divmod/4, because many bigint algorithms can
produce both div and mod at the same time.

Trying to port a SWI-Porlog program I get:

?- use_module('/draft.pl').
{Compiling /draft.pl
ERROR: (lns 27-30) Predicate divmod/4 undefined in source
ERROR: Aborted module compilation
}

Could this be added to Ciao Prolog, especially the playground?

jfmc commented

Thanks for the suggestion!

You may try this:

divmod(Dividend, Divisor, Quot, Rem) :-
    Rem is Dividend mod Divisor,
    Quot is (Dividend - Rem) // Divisor.

which actually gives an implementation for div/3 (before we introduce it as an arithmetic expression):

div(Dividend, Divisor, Quot) :-
    Rem is Dividend mod Divisor,
    Quot is (Dividend - Rem) // Divisor.
jfmc commented

No, Ciao uses its own implementation of bignums. Of course we could add it, but is there any example where performance of this operation is critical?

It is better not to close it because it is not solved. Open issues are reminders of things that need to done or would be good to do, for which we thank you. Unfortunately time is limited, snd thus when to get something done is indeed a matter of priorities, as @jfmc implied.