[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some advice on a "simple" thing...

From: Sean Charles
Subject: Re: Some advice on a "simple" thing...
Date: Wed, 9 Apr 2014 21:44:52 +0100

> One of the cool things about Edinborough syntax Prolog is the use of 
> 'operators' - they are just syntactic sugar for function terms. (Cambridge 
> syntax prolog looks like Lisp - I don't think any implementations still exist 
> that use this syntax.)

Is that the syntax used in Art of Prolog? I recognise it from there I am sure.

>       foo(a - b, c + d, e = f) is semantically equivalent to
>       foo(-(a, b), +(c, d), =(e,f))
> '-(a,b)' does not have a particular interpretation in Prolog, it's meaning is 
> determined (in this case) by what 'foo' does with it and what other clauses 
> referencing 'foo' do with it.

OK, so the “traditional” operators are defined but they are given no special 
meaning unless used with “is”. Correct??

> This is how arithmetic operations are defined using the 'is' builtin. The 
> 'is' builtin gets a nested function term that uses functors that it 
> interprets as arithmetic operations:
>       X is 3 + 4 *  2 * 7.
> is the same as
>       X is +(3, *(4, *(2, 7))).
> The 'is' builtin applies common arithmetic processing to this nested 
> structure to unify a numeric value 59 with X.

Within the context of “is”, does the functor know what it has to do with its 
arguments or is it the “is” processing code the decides to add, subtract etc. ? 
I guess that’s an implementation detail and would vary between vendors.

> Outside of 'is' and some special comparison builtins, the functors that look 
> like arithmetic operators have no particular semantics:
>       Y = 3 + 4 * 2 * 7,
>       (Z + W) = Y.
> binds Z to '3' and W to '4 * 2 * 7'. There is no arithmetic processing done 
> in this case.

That I understand BUT how does the unification engine know to pattern 
match….hang on, a light is starting to come on now… by rewriting the expression 

   Y = +(3, +(4, *(2, 7))),
    +(Z, Y) = Y.

I can now see that unification will match Z to 3 and Y to the remainder. 
YES!!!! HAHAHA Eureka.   I remember making myself write stuff out in Haskell 
and not using the >> operator until I “got it”, this feels the same. 
Excellent!! (Good job ! is free to type).

Lindsey and Daniel, thankyou very much for your replies. I have taken another 
step forward!  This is sometimes the downside of not having “done CS at school” 
and had the supreme luxury of all the hours in the day to learn and reflect. 
Great. This is truly great, well, for me it is, I am sure plenty of readers are 
thinking, “Well like yeah, I thought everybody knew that from CS101”.

Thanks!  :) Now I can begin world domination with GNU Prolog….


reply via email to

[Prev in Thread] Current Thread [Next in Thread]