Re: arithmetic_function (SWI)



Just two more issue regarding arithmetic function handling in SWI Prolog.
In particular, I got the following segmentation fault errors, that I think
one might avoid to see.

?- arithmetic_function(c/0).
yes
?- X is c. % *see later

?- arithmetic_function(c/0).
yes
?- assert(( c(_) :- throw(error(instantiation_error, _)) )). % or some other
exception
yes
?- X is c. % *see later

Both goal* return this (I marked them with an asterisk):
ERROR: is/2: Undefined procedure: c/1
ERROR: is/2: Caught signal 11 (segv)

I do not know, but they seem bugs. Arent they?
Thanks again.
M

"Mauro Di Nuzzo" <picorna@xxxxxxxxx> ha scritto nel messaggio
news:yzVPf.64$8g7.61@xxxxxxxxxxxxxxxxxxxxxx
Thank you very much Jan.
Having understood what you said me, I tried to put an arithmetic function
in
a module by this way:

--------
% name.pl
:- module(some, []). % I can export here the function c/0 in the same
way
I export, for example, an operator.
:- arithmetic_function(c/0).
c(10).
% eof
--------

?- consult('name.pl').
yes
?- X is c.
ERROR: is/2: Arithmetic: 'c/0' is not a function

So I am unable to use c/0 from the toplevel (or just from a module other
than 'some').
What I want is to have the arithmetic function c/0 imported into context
module, and not the predicate c/1.
Does a method to achieve this exist, since module export declaration does
not include arithmetic functions?
:)
M

"Jan Wielemaker" <jan@xxxxxxxxxxxxxxxxxxx> ha scritto nel messaggio
news:slrne105s3.4b0.jan@xxxxxxxxx
On 2006-03-09, Mauro Di Nuzzo <picorna@xxxxxxxxx> wrote:
Hi All.
This is an issue regarding arithmetic_function/1 predicate under SWI
Prolog.

Suppose I define a new arithmetic function, namely a constant c/0, in
this
way

:- arithmetic_function(c/0).
c(10).

Consider no changes in the context module when I consult it from the
toplevel.
Then I try:

?- X is c*2.
X = 20

That's ok. But I should have written:

?- c(Y).
Y = 10

So I can really access the predicate c/1. Instead, for SWI builtin
arithmetic function, this is not the case.
In fact, this happens:

?- Z is e.
Z = 2.71828

?- e(E).
ERROR: undefined procedure: e/1

So it seems that predicate e/1 associated with arithmetic function e/0
it is
asserted elseWHERE.
Finally, my question, WHERE?

Nowhere. All built-in arithmetic functions are connected to C-functions
using some internal interface (see pl-arith.c). One of these exploits a
call-back to Prolog to make predicates available as functions.

In other words, how can I handle arithmetic functions so that
associated
predicates (with arity + 1) are, let's say, invisible?

You can't. You can put them in a module though.

--- Jan




.



Relevant Pages

  • Re: arithmetic_function (SWI)
    ... This is an issue regarding arithmetic_function/1 predicate under SWI Prolog. ... Suppose I define a new arithmetic function, namely a constant c/0, in this ... So it seems that predicate e/1 associated with arithmetic function e/0 it is ...
    (comp.lang.prolog)
  • arithmetic_function (SWI)
    ... This is an issue regarding arithmetic_function/1 predicate under SWI Prolog. ... Suppose I define a new arithmetic function, namely a constant c/0, in this ... So it seems that predicate e/1 associated with arithmetic function e/0 it is ...
    (comp.lang.prolog)
  • Re: arithmetic_function (SWI)
    ... So I am unable to use c/0 from the toplevel (or just from a module other ... What I want is to have the arithmetic function c/0 imported into context ... This is an issue regarding arithmetic_function/1 predicate under SWI ... So it seems that predicate e/1 associated with arithmetic function e/0 ...
    (comp.lang.prolog)
  • Re: arithmetic_function (SWI)
    ... What I want is to have the arithmetic function c/0 imported into context ... Does a method to achieve this exist, since module export declaration does ... Declaring a function f/n simply means you also have the predicate ... The proper way around might be to allow exporting functions ...
    (comp.lang.prolog)