2
votes

I'd like to know why I get an error with my SWI Prolog when I try to do this:

(signal(X) = signal(Y)) :- (terminal(X), terminal(Y), connected(X,Y)).
terminal(X) :- ((signal(X) = 1);(signal(X) = 0)).

I get the following error

Error: trabalho.pro:13: No permission to modify static procedure '(=)/2'

It doesn't recognize the "=" in the first line, but the second one "compiles". I guess it only accepts the "=" after the :- ? Why?

Will I need to create a predicate like: "equal(x,y) :- (x = y)" for this?

2
just rename it equal_signals(X,Y):- .... =/2 is a system predicate, you can not and need not change it here.Will Ness
(Signal(t) = 1) OR ( Signal(t) = 0) translates to Prolog as signal(T,S), (S=1 ; S=0). this if you have a "function" signal which "returns" results in its 2nd argument. But you don't include any explanations in your questions, we're left guessing. Perhaps you could start by explaining what you have, in which "world" is your question set, and what do you want to achieve.Will Ness

2 Answers

1
votes

Diedre - there are no 'functions' in Prolog. There are predicates. The usual pattern goes

name(list of args to be unified) :- body of predicate .

Usually you'd want the thing on the left side of the :- operator to be a predicate name. when you write

(signal(X) = signal(Y))

= is an operator, so you get

'='(signal(X), signal(Y))

But (we assume, it's not clear what you're doing here) that you don't really want to change equals. Since '=' is already in the standard library, you can't redefine it (and wouldn't want to)

What you probably want is

equal_signal(X, Y) :- ... bunch of stuff... . or

equal_signal(signal(X), signal(Y)) :- ... bunch of stuff ... .

This seems like a conceptual error problem. You need to have a conversation with somebody who understands it. I might humbly suggest you pop onto ##prolog on freenode.net or some similar forum and get somebody to explain it.

0
votes

Because = is a predefined predicate. What you actually write is (the grounding of terms using the Martelli-Montanari algorithm):

=(signal(X),signal(Y)) :- Foo.

You use predicates like functions in Prolog.

You can define something like:

terminal(X) :- signal(X,1);signal(X,0).

where signal/2 is a predicate that contains a key/value pair.

And:

equal_signal(X,Y) :- terminal(X),terminal(Y),connected(X,Y).