Re: [eclipse-clp-users] Accessing Eclipse predicates

From: Kish Shen <kisshen_at_...5...>
Date: Fri, 16 Aug 2013 18:41:51 +0100
On 16/08/2013 01:47, Volkan Unsal wrote:
> Being new to Eclipse, I am trying to understand some basic concepts. I
> don't understand why are some Eclipse predicates not available from inside
> loops. For example:
> # test.ecl
> main :-
>    (foreach(A,[1,2]) do
>        Z is string(A),
>        writeln( Z )
>      ).

If you have Z is string(A) outside a loop, you would get the same error.

The problem you are seeing is because is/2 expects an arithmetic 
expression on the right-hand side, and if you look at the documentation 
for is/2 (which you can get by "help is/2" at the top-level):

 >   This evaluation mechanism outlined above is not restricted to the
 >   predefined arithmetic functors shown in the table.  In fact it 
works for
 >   all atoms and compound terms.  It is therefore possible to define a new
 >   arithmetic operation by just defining an evaluation predicate.
 >   Similarly, many ECLiPSe built-ins return numbers in the last argument
 >   and can thus be used as evaluation predicates (e.g.cputime/1, random/1,
 >   string_length/2, ...).  Note that recursive evaluation of arguments is
 >   only done for the predefined arithmetic functions, for the others the
 >   arguments are simply passed to the evaluation predicate.

So string(A) is treated as a call to a predicate string/2, which is not 
defined, as reported by the error message you saw:

> $ eclipse -b test.ecl -e main
> calling an undefined procedure string(1, _105343) in module eclipse
> abort

> These are available from the command line when I query the data, but not
> from within the program. How do I do type checking on the variables if I
> can't use these...?

is/2 is intended (as in other Prologs) for evaluating an arithmetic 
expression. If you want to do type checking, you should not put the type 
check predicate on the rhs of is/2. You should just call it, e.g.

    (foreach(A, As) do string(A))

> Almost exactly the same problem with comparison operators:
> fn1 :-
>    (foreach(A,[1,2]) do
>        Z is compare("<", A, 1),
>        writeln( Z )
>      ).
>    %% calling an undefined procedure compare("<", 1, 1, _103944) in module
> eclipse
>    %% abort

Again, you should just have compare("<", A, 1) on its own, although here 
you can write:

1 is compare("<", A)

because the last argument does return a number.


Received on Fri Aug 16 2013 - 17:42:33 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:30 CEST