The beginnings of a stack trace #2631
Replies: 5 comments 10 replies
-
One of the cute dumb things I figured out is you can "hook" a goal without modifying it if you statefully track which goals you were just looking at :P It is sad how long that took me to figure out today 😭 user:goal_expansion(G, G) :-
bb_get(error_stack, Stack),
bb_get(previous, X),
prolog_load_context(module, Module),
prolog_load_context(term_position, position_and_lines_read(Pos, Line)),
dif(G, X), %% <--- ensure we aren't infinitely expanding the same goal
bb_b_put(previous, G),
append(Stack, [(position(Pos), line(Line), module(Module), G)], Stack1),
bb_b_put(error_stack, Stack1). |
Beta Was this translation helpful? Give feedback.
-
Very interesting, will it work as a module: |
Beta Was this translation helpful? Give feedback.
-
This approach is indeed extremely interesting! Related to tracing, I once wrote Emacs definitions that let you interactively step through Prolog code, by highlighting the goals that are being executed: https://www.metalevel.at/etrace/ Personally, I do not recommend such a "stepping through" the computation, because it detracts us from implementing and applying better approaches. Nevertheless, I consider it interesting to think about which features a Prolog system must provide to make this approach possible. It would be great to implement this approach more portably, so that it can be used for instance with Scryer Prolog too, and your idea of using the existing expansion mechanisms together with a few predicates that let us locate the positions of terms we need to know could be a very promising and conceptually elegant solution for this! |
Beta Was this translation helpful? Give feedback.
-
I'm starting to think this is a fools errand. Full post-mortem will have to wait, though. |
Beta Was this translation helpful? Give feedback.
-
I have another comment about your approach. It is hard to control if your particular goal expansion will be performed before or after other possible expansions. That means that if someone else also does some sort of term/goal manipulation, then stack trace will be unreliable. Maybe it will be possible to design an elegant goal expansion mechanism that can guarantee order of transformations... |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions