question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

goal_expansion/2 not being called

See original GitHub issue

I’m trying to workaround the format/2-3 predicates not accepting an atom in the first argument by using the goal_expansion/2 predicate as follows:

var program = 
	":- use_module(library(format))." +
	"goal_expansion(format(A,L),format(Cs,L)) :- atom(A), atom_chars(A,Cs)." +
	"foo :- format('~w~n',[hello]).";
session.consult( program );

session.query( "foo." );
session.answers( x => console.log( pl.format_answer(x) ) );

But the goal_expansion/2 predicate doesn’t seem to be called:

$ node ./tp.js 
uncaught exception: error(type_error(list, ~w~n), /(format_, 2))
false.

I also tried, with no success, using separate consult calls:

session.consult( ":- use_module(library(format))." );
session.consult( "goal_expansion(format(A,L),format(Cs,L)) :- atom(A), atom_chars(A,Cs)." );
session.consult( "foo :- format('~w~n',[hello])." );

The expanding a goal is expected to recursively call the goal_expansion/2 predicate until a fixed-point is reached. But in this case it seems like the predicate is never called.

P.S. I have a simpler alternative to workaround the limitations of the format/2-3 predicates.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jariazavalverdecommented, May 22, 2020

Fixed. It was a bug due to changing the default value of the quoted writing option to false.

TODO: At the moment, term and goal expansion only looks for predicates term_expansion/2 and goal_expansion/2 defined in the user module.

0reactions
triskacommented, May 22, 2020

One example is from library(clpz), which works with SICStus:

with_local_attributes(Vars, Goal, Result) :-
        catch((Goal,
               maplist(del_all_attrs, Vars),
               % reset all attributes, only the result matters
               throw(local_attributes(Result,Vars))),
              local_attributes(Result,Vars),
              true).

Here, Goal is invoked dynamically, and it is used with goals that need goal expansion. This goal expansion is not applied at compile time, because the Prolog compiler only sees with_local_attributes/3 invoked.

However, now that I think about it, with a suitable meta_predicate/1 declaration for with_local_attributes/3, the compiler could probably look into the argument, and expand it too? That would solve the issue without any overhead at runtime.

That being said, I would still find runtime goal expansion for the call/N family of predicates desirable, and it can be implemented with close to no overhead. If it is too slow, I would regard that as a sign that the implementation needs to be improved so that it becomes fast.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SWI-Prolog 5.6 - Computer Science
The predicate goal expansion/2 is first called in the module that is being compiled, and then on the user module. If Goal is...
Read more >
How to get to a fixed point with goal expansion? - SWI-Prolog
I don't think anyone, including the original author, is comfortable with it. A better solution could be to allow marking a goal to...
Read more >
Function is not being called React native - Stack Overflow
I have a function called setSTNo and it's not being called. I tried so many times but couldn't figure out the error. Need...
Read more >
SWI-Prolog 3.2
This manual does not describe the full syntax and semantics of Prolog, ... DCG translation of free variables now calls phrase/3, which has...
Read more >
SWI-Prolog 3.2 - CiteSeerX
This manual does not describe the full syntax and semantics of Prolog, ... DCG translation of free variables now calls phrase/3, which has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found