You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
as hinted in #2720 (comment), several tools may benefit from being able to meta-interpret !/0, at the very least for analytic purposes and maybe in the future also for automated suggestions and rewrites using more recent constructs with more desirable algebraic properties.
I think it is possible to meta-interpret !/0 with the standard control constructs catch/3 and throw/1. Declaratively, !/0is true, and any faithful emulation must succeed exactly once.
I therefore suggest the following predicate to emulate !/0 with exceptions:
cut.
cut :- throw(cut).
This succeeds, and throws an exception on backtracking.
We can catch the exception with catch/3. For example:
?- catch(((X=1;X=2),cut,member(Y,"abc")), cut, false).
X = 1, Y = a
; X = 1, Y = b
; X = 1, Y = c
; false.
This suggests, as a rough outline for how meta-interpretation could be performed:
mi((Before,!,After)) :- % needs work
catch((mi(Before),cut,mi(After)), cut, false).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Dear all,
as hinted in #2720 (comment), several tools may benefit from being able to meta-interpret
!/0
, at the very least for analytic purposes and maybe in the future also for automated suggestions and rewrites using more recent constructs with more desirable algebraic properties.I think it is possible to meta-interpret
!/0
with the standard control constructscatch/3
andthrow/1
. Declaratively,!/0
is true, and any faithful emulation must succeed exactly once.I therefore suggest the following predicate to emulate
!/0
with exceptions:This succeeds, and throws an exception on backtracking.
We can catch the exception with
catch/3
. For example:This suggests, as a rough outline for how meta-interpretation could be performed:
I hope this helps!
All the best,
Markus
Beta Was this translation helpful? Give feedback.
All reactions