goal_expansion/2 not being called
See original GitHub issueI’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:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed. It was a bug due to changing the default value of the
quoted
writing option tofalse
.TODO: At the moment, term and goal expansion only looks for predicates
term_expansion/2
andgoal_expansion/2
defined in theuser
module.One example is from
library(clpz)
, which works with SICStus: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 seeswith_local_attributes/3
invoked.However, now that I think about it, with a suitable
meta_predicate/1
declaration forwith_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.