I am writing some code that make heavy use of dictionaries, to provide kind of fluent interface (not to be mixed up with SWI-Prolog fluent). However “non-functional” calls like Var.pretty_print()
are currently not expanded. Is there a good reason why this isn’t supported?
Because it’s not a function (or a predicate) call? – It’s a term.
This should work:
call(Var.pretty_print)
although its expansion isn’t the most efficient:
call(( '.'(Var, pretty_print, A), call(A))).
and call(Var.pretty_print, Arg)
isn’t supported.
Thanks for the hint, I now realized that foo{}.bar()
actually isn’t infix syntax for '.'(foo{}, bar())
, but it actually expands to:
'.'(foo{}, bar(), A),
call(A).
So there is a somewhat hacky way of defining:
foo:debug(Dict, Impl) :-
Impl = format("Printing ~w", [Dict]).
then
test :-
foo{a: 1, b: 2}.debug().
works However the expansion works differently in the interactive mode and fails with
Unknown procedure: ('.')/2