Re: [eclipse-clp-users] X is p(a) +1. from Apt/Wallace book

From: Kish Shen <kish.shen_at_...6...>
Date: Thu, 17 Jun 2021 14:08:09 +0100
Hi Doug,

This is how ECLiPSe evaluate expressions, and is discussed in the user manual:

http://eclipseclp.org/doc/userman/umsroot046.html

and more specifically in the 'User defined arithmetic function' section.

This functionality is also available in other contexts, e.g. for
constraint arithmetic expressions in IC/GFD.

THe reason ECLiPSe can do this is because ECLiPSe (and Prolog in
general) code are all valid data structures (terms) in the language,
and expressions are just terms that can be evaluated..'Normal'
arithmetic operators like +/2 are interpreted as functions, and
ECLiPSe just extend this to user defined functions.

Note that ECLiPSe does have built-in such as +/3:

[eclipse 5]: +(3,4,X).

X = 7

Cheers,

Kish



On Thu, Jun 17, 2021 at 1:18 PM Doug Edmunds <dougedmunds_at_...6...> wrote:
>
> In the Apt/Wallace book Constraint Log Programming Using Eclipse (2007),
> Ch 3 "Arithmetic in Prolog" on pages 45-46 there is this code:
> -------
> To save explicitly introducing such extra variables, ECLiPSe supports
> for is/2 a functional syntax. Let us suppose p/2 is a predicate whose
> last argument is numeric, viz.
>
> p(a, 1).
> p(b, 2).
>
> Then p/1 can be used as a function when it occurs on the right-hand side
> of is, for example:
>
> [eclipse 10]: X is p(a)+1.
>
> X = 2
> Yes (0.00s cpu)
>
> --------
>
> How does this work?  I don't understand how p(a,1) becomes numeric.
>
> Can you point me to some reference to "predicate whose last
> argument is numeric" in the manuals?
>
> Thanks.
>
> -DAE
>
>
>
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
Received on Thu Jun 17 2021 - 13:08:34 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:21 CEST