3
votes

I've got a prolog source file that allows me to use the ($)/2 meta predicate fine, but when I convert it to a module as follows, I get syntax errors wherever $ used to work:

:- module('mymodule', [mypred1/2, mypred2/3, ($)/2]).
:- use_module(library(func)).

I've tried reexport as well, to no avail.

So doing things like X is mypred1$"something" gives me a syntax error. However, removing the :- module(... line from the source file fixes the issue.

How do I get $ functioning properly within a module?

1

1 Answers

3
votes

The problem appears when you use a custom infix operator ($)/2 and introduce module "boundaries".

When implementing Prolog lambdas, Ulrich Neumerkel faced the same problem! For a SWI-specific fix, check out and study lambda.pl—it starts with:

:- module(lambda, [(^)/3, (^)/4, (^)/5, (^)/6, (^)/7, (^)/8, (^)/9, (^)/10,
                   (\)/1, (\)/2, (\)/3, (\)/4, (\)/5, (\)/6, (\)/7, (\)/8,
                   (+\)/2, (+\)/3, (+\)/4, (+\)/5, (+\)/6, (+\)/7, (+\)/8, (+\)/9,
                   op(201,xfx,+\)]).

That's it!

Also, read the SWI manual on module/2 and you're good to go!