Re: [swipl] Use arithmetic_function/1 inside a module
Wouter Beek <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAE1un7MJWLqkpAzitu3N66OX1_aGUUbGkMD6mma_UshmzzEJHw@mail.gmail.com> |
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 >