how to create a new directive

Adam Russell <[email protected]> Thu, 7 Aug 2025 15:56:57 +0000
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <MN2PR07MB71664B4E3F5E61F28465F278D42CA@MN2PR07MB7166.namprd07.prod.outlook.com>
--_000_MN2PR07MB71664B4E3F5E61F28465F278D42CAMN2PR07MB7166namp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am stuck doing something which I thought was going to be simple, but now =
I am not sure if it is possible.

Let's say I have a predicate like so.

    something(X):-
        write(X), nl.

And I use op/3 like so

    op(1150, fx, something).

I expect that I can now use this as a new directive such as

:-something(abc).

But this does not work. I simply get an error

    warning: unknown directive (something)/1 - maybe use initialization/1 -=
 directive ignored

Of course using

    :-initialization(something(abc)).

will work.

Is it simply not possible to define a new directive in GNU Prolog? Or am I =
making an error somewhere?




--_000_MN2PR07MB71664B4E3F5E61F28465F278D42CAMN2PR07MB7166namp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
I am stuck doing something which I thought was going to be simple, but now =
I am not sure if it is possible.</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
Let's say I have a predicate like so.</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
&nbsp; &nbsp;</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
&nbsp; &nbsp; something(X):-</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
&nbsp; &nbsp; &nbsp; &nbsp; write(X), nl.</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
And I use op/3 like so</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
&nbsp; &nbsp; op(1150, fx, something).</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
I expect that I can now use this as a new directive such as</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
:-something(abc).&nbsp;</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
But this does not work. I simply get an error</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
&nbsp; &nbsp; warning: unknown directive (something)/1 - maybe use initiali=
zation/1 - directive ignored</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
Of course using&nbsp;</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
&nbsp; &nbsp; :-initialization(something(abc)).</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
will work.</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
Is it simply not possible to define a new directive in GNU Prolog? Or am I =
making an error somewhere?</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"line-height: normal; margin: 0px; font-family: Calibri, Helve=
tica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class=3D"elementTo=
Proof">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;=
 color: rgb(0, 0, 0);" class=3D"elementToProof">
<br>
</div>
</body>
</html>

--_000_MN2PR07MB71664B4E3F5E61F28465F278D42CAMN2PR07MB7166namp_--