New library(macros) - Reply 1

Very cool!

One issue that I found is that library(macros) seems to conflict with library(clpfd) with set_prolog_flag(clpfd_monotonic, true), where CLP(FD) also relies on #/1 terms.

This is a bit of an edge case, but for example, if we have in macros_test.pl:

:- module(macros_test, [baz/1]).

:- use_module(library(clpfd)).

:- set_prolog_flag(clpfd_monotonic, true).

:- use_module(library(macros)).

#define(foo, bar).

baz(X) :- #(X) #= 1 + 2.

Then trying to load this file yields an instantiation error:

$ swipl macros_test.pl
ERROR: .../macros_test.pl:11:
ERROR:    Arguments are not sufficiently instantiated
ERROR: Exported procedure macros_test:baz/1 is not defined
Welcome to SWI-Prolog (threaded, 64 bits, version 9.1.10-9-g1dd0edbaa)

I have been dreaming about constants for a long while already … makes live so much easier.

I don’t think it’s an edge case at all. Working with integer arithmetic is a very common place to have this kind of constants defined in the source code, and not being compatible one library with the other will be a bummer.

Good points. Pushed a commit that only considers #Term for expansion if Term is a Prolog callable term (atom or compound). Instead of raising an error, #Var is now passed unmodified.