Re: [swipl] Use arithmetic_function/1 inside a module

Jochem Liem <[email protected]> Sat, 5 Apr 2014 09:40:15 +0300
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CABryw9R_+aKLbWWCyZJo4UMu0SA2B9NSa1jspv_-6ui909wuvg@mail.gmail.com>
Hi Wouter,

Ah, now I understand what you are trying to achieve. I've also tried
to get it to work, but was unable.
The documentation indicated that arithmetic_function is deprecated and
that "pure Prolog user-defined arithmetic functions that has been
dropped in SWI-Prolog 5.11.23."

I'm not sure if it is still possible at all.

Cheers,
Jochem


2014-04-01 20:23 GMT+03:00 Wouter Beek <[email protected]>:
> On Tue, Apr 1, 2014 at 7:16 PM, Jochem Liem <[email protected]> wrote:
>> Why are you using: 'X is xsd_div(7, 2).' ?
>> You can just do 'test_arithmetic:xsd_div(7,2,X)'.
> But then it's no longer a function? I want nested expressions to
> evaluate out-of-the-box like the swipl builtin arithmetic functions
> do. For example:
> ~~~{.pl}
> TimeOnTimeline is
>     % Year
>     31536000 * Y2
>     % Leap-year days
>     + 86400 * (Y2 xsd_div 400 - Y2 xsd_div 100 + Y2 xsd_div 4)
>     % Month
>     + 86400 * D3
>     % Day
>     + 86400 * D2
>     % Hour
>     + 3600 * H2
>     % Minute
>     + 60 * MM3
>     % Second
>     + S2.
> ~~~
>
> (PS: For these examples is could use the builtin function div i.o.
> xsd_div, but I want to be able to define different functions as well.)
>
> Cheers,
> Wouter.
>>
>> ?- test_arithmetic:xsd_div(7,2,X).
>> X = 3.
>>
>> Cheers,
>> Jochem
>>
>> On Tue, Apr 1, 2014 at 8:00 PM, Wouter Beek <[email protected]> wrote:
>>> Hi list,
>>>
>>> Is it possible to define an arithmetic function inside a module?
>>>
>>> Sample file:
>>> ~~~{.pl}
>>> :- module(test_arithmetic_1, []).
>>> :- use_module(library(arithmetic)).
>>> :- arithmetic_function(xsd_div/2).
>>> xsd_div(X, Y, Z):-
>>>   Z is floor(X / Y).
>>> ~~~
>>>
>>> Usage:
>>> ~~~
>>> swipl -s test_arithmetic_1.pl
>>> ?- X is xsd_div(7, 2).
>>> Error: Arithmetic: `xsd_div(7,2)' is not a function
>>> ~~~
>>>
>>> I have no problem with using arithmetic functions defined in non-module files.
>>>
>>> ---
>>> Cheers!,
>>> Wouter.
>>>
>>> E-mail: [email protected]
>>> WWW: www.wouterbeek.com
>>> Tel.: 0647674624
>>> _______________________________________________
>>> SWI-Prolog mailing list
>>> [email protected]
>>> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>>
>>
>>
>> --
>> Jochem Liem, PhD
>> http://jochemliem.wordpress.com
>>



-- 
Jochem Liem, PhD
http://jochemliem.wordpress.com