Understanding Scryer's stack frame management #2654
-
Hi,
As I understand it, Scryer-Prolog manages its call stack on the heap, so a (non-tail call optimized) recursive algorithm may pile up stack frames on the heap but never risks breaching the underlying scryer-prolog process' fixed-size stack. Is that right? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
From this description, it seems that one of these programs is faster than the other, for a specific test case and for a specific version of Scryer Prolog. As to why, there are many potential reasons for this. For instance, As I see it, the direction of Prolog code and engine developments should be:
An example of what we don't want is: a. We choose a specific version of Scryer Prolog. Personally, I think that understanding Scryer Prolog's stack frame management is not required for writing elegant Prolog code. It may even be an obstacle because it costs too much attention and detracts us from finding more elegant solutions. If the available memory is exceeded, we expect Scryer to throw an appropriate exception that can be caught within Prolog. In your specific case, the more elegant, shorter and more natural version is also faster, and that's in my experience also the typical situation. |
Beta Was this translation helpful? Give feedback.
Personally, I aim for correctness and elegance. We can use Prolog itself to query the defined relations in various ways, and test them very exhaustively.
In this concrete example, let's ask Prolog what the predicate means. Let's start with the most general query: Which solutions are there in general?
From this, it appears that the entire relation can be defined with a single fact. On the other hand, this is probably not the intended relation, so there is likely a mistake in the code.
Regarding efficiency: For large data structures, the used algorithms must generally stay sub-quadratic, and otherwise quickly become infeasible.