Re: defining operators with a result



Richard Szopa wrote:
First of all, thank you all for your answers.

I think that the solution proposed by Glenn Lieding doesn't really
solve my problem. Having to adapt every predicate to deal with the mton
structure won't make my code more compact or more readable. Also, I
would like to be able to use my notation in built-in predicates, like
for example reverse and so on.

On the other hand, GRIPS goes much too far for me--I realize that
Prolog uses relational notation and I'm quite happy with it. Also, I
find remaining understandable for the rest of Prolog programmers quite
important. ;-)

The idea of trying to add this sugar to Prolog came to me when I found
that I use [m..n] quite often in my pseudo-Prolog code, but when I
translate it into Prolog, it gets somehow more obscure.

Anyway, an additional question: how would one define in Prolog |, the
cons operator, if it wasn't built in the language and f one wanted it
work exactly as | works now in [Head|Tail]? Or, if one wanted to be
able to use the '@' sign in one's Prolog programs instead of '|'? Is
it possible?

Of course, hacking the source of the interpreter is not the kind of
answer I expect ;-)

-- Richard


[did nobody suggest term expansion for this ? or have I overlooked something]

You can first of all define .. as an infix operator with precedence and
associativity of your liking, but so that [X..Y] parses correctly -
:- op(100, xfx, ..).
is just one possibility that works for me.

Next write a piece of term expansion that transforms e.g. the clause

a(N) :- write([3..N]).
into
a(N) :- x2y(3,N,L), write(L).

and

f([5..9]).
into
f(L) :- x2y(5,9,L).

etc.

That's not very difficult.

And you are basically done - except that you need to decide what to do
with meta predicates, and maybe you want this transformation to be local to
a module ...

Probably CIAO would give you good support for doing all this (and more :-)
But is is doable in SWI as well of course.

Cheers

Bart Demoen
.



Relevant Pages

  • Re: OO versus RDB
    ... There is a very simple mapping from RM to PROLOG. ... a representation based on predicates, ... 'connection' comes from the fact that PROLOG stores rules about facts ...
    (comp.object)
  • Re: OO versus RDB
    ... There is a very simple mapping from RM to PROLOG. ... store knowledge using predicates. ... applied to a physical representation of a relational model. ...
    (comp.object)
  • Re: Prolog, memory management and memory leaks
    ... It depends on what you mean by a memory leak. ... Did the programmer mess up, ... the Prolog implementation you are working with). ... non-deterministic predicates in not always perfect. ...
    (comp.lang.prolog)
  • Re: Cross-Compiler development (MasterProlog/SWI/SICStus)
    ... In most Prolog applications, there are usually a small set of ... top predicates and a bigger number of auxiliary predicates. ... of the object encapsulating them. ... the configuration file for your Prolog compiler, ...
    (comp.lang.prolog)
  • Re: What should the semantics of hierarchical modules be?
    ... > Brian Hulley wrote: ... >>>the pure Prolog. ... But Prolog) Predicates are global and there are no objects or types to ... and write "foo" and let prolog discover what I meant by searching" ...
    (comp.lang.prolog)