-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No easy way to nullify a term using term_expansion without hacks #2623
Comments
You can expand it for example to: nullified :- false. Or use for example the predicate name |
Nullification works for me: ?- [user].
term_expansion(b, []).
a.
b.
c.
?- a.
true.
?- b.
error(existence_error(procedure,b/0),b/0).
?- c.
true.
?- |
@hurufu: No, it has only replaced You can see the issue with: term_expansion(b, []). a. b. c. b. yielding: % Warning: overwriting []/0 because the clauses are discontiguous true. |
Wow, indeed. Silly me. I think it should count as a bug. Then yes, the only solution I see is currently to expand to known "bad" predicate, as you have proposed. Or even better to some undefined dynamic predicate, so it would fail faster. UPDT: As an example I've tested this behavior on all prologs that I'm currently being packaging. It looks like every Prolog handles it differently |
@hurufu: I think the intuition is justified though, that an expansion of |
A fact Note that in SICStus, a single
In SWI,
|
Something like this should work and be very fast: :- initialization(abolish(nil/0)).
:- dynamic(nil/0).
term_expansion(b, nil).
a.
b.
c.
b. |
I didn't even realize until just now that you could run |
@hurufu: An ideal solution would not affect any existing predicate definitions, if such definitions are also present in the source file. |
My example didn't contain code executed in a toplevel, or was it just an observation?
then fixing behavior of |
Yes, I agree! This means the empty list of terms, so vanishing. |
user:term_expansion((:- womp), (:- initialization(true))). this is turning out to be the best workaround so far! |
I'll leave this open because I assume that my workaround is probably not considered "acceptable" but it's certainly good enough for me. |
This solution will slightly increase startup time if you nullify a lot of terms. |
I know you are used to thinking of startup performance down to the clock cycle level but my comparisons are to Unity, Java, and LLM startup speeds haha. For me I'm willing to take the hit! |
So this turns out not to be a great approach. Until we can nullify terms, I think it's better to use a custom operator directive. :- op(1200, fx, :->).
':->'(_).
user:term_expansion((:-> womp), (:-> not_womp)) :-
do_stuff. Using |
Update: Workaround
tl;dr
There should be some way to nullify terms in term expansion without needing to result to
(:- module(random_name, [])
, probably by doinguser:term_expansion(<pattern>, []).
Overview
There is no easy way to nullify terms using term expansion, and the same is probably true for goal expansion though I haven't tested it yet.
By nullify I mean "expand to zero terms". So to nullify term
(b)
from the following:We would expect the nullification of
(b)
to result in:Motivation
I like to add the following to my scripts these days:
The way I don't get the following warning in commented queries
There should be some way to nullify terms in term expansion without needing to result to
(:- module(random_name, [])
, probably by doinguser:term_expansion(<pattern>, []).
:
You can also use the same technique to make custom
:-
directives:(this technique is necessary because
:- initialization(something)
comes after term_expansion, so if you want to used initialized state, you must initialize the state in the term expansion lifecycle phase rather than then initilization lifecycle phase)Explanation of Workaround
Note the hack: (:- module(a, []). That's because this is the only way I know of to NULLIFY a term, equivalent to a comment macro in lisp:
Exploration of Current Behavior
These are the following techniques you would probably expect to work in Prolog:
Doesn't work, the term will remain unchanged and then eventually called as is resulting in the same warning. (Note: this is expected, I think. I don't think
false
should nullify the term).The following should probably splice or expand into 0 terms in place of the current term:
however it results in the following warnings:
which indicate to me that
[]
is being treated as a fact.You can get the same warning by doing:
Expectation vs Reality
The net result of this is that you can't make a side-effecting user-defined directive with the
:-
operator because you get a domain error:results in
unless you do something like:
You can't simply do
because that will still result in an unchanged
(:- womp)
which results inExpectation
There should be some way to nullify terms in term expansion without needing to result to
(:- module(random_name, [])
, probably by doinguser:term_expansion(<pattern>, []).
The text was updated successfully, but these errors were encountered: