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
in the past few days, I tried to improve the speed of format_//2 and related constructs. format_//2 is a DCG nonterminal, and often invoked as part of an argument to phrase/2. For instance, as already mentioned in #2364, it occurs in one of my programs as:
It came as a surprise to me that 3 straight-forward clauses of goal_expansion/2 suffice to improve the running time of each of these constructsin all contexts in which they can arise, even when they are "nested" in completely different constructs as in the examples above, where format_//2 occurs as a direct argument of phrase_to_stream/2 and (',')//2, and as an indirect argument of phrase/2.
For instance,library(format) can, and per #2363 also does, instruct Scryer Prolog to expand every occurrence of a call to format/3 in every application program or library directly to its definition, by defining:
In the resulting expansion, format_//2 is used as an argument to phrase_to_stream/2. I originally thought that any further automated expansion of such an occurrence of format_//2 as an argument to phrase_to_stream/2 in particular would have to be handled as a special case, in addition to cases where it occurs as a direct or indirect argument of phrase/2. However, it turns out that I did not have to do anything special, because phrase_to_stream/2 is declared as a meta-predicate in such a way that Scryer Prolog knows that its first argument is a goal and hence automatically applies goal expansion to this argument even correctly taking into account the additional declared arguments:
:- meta_predicate(phrase_to_stream(2, ?)).
I thus feel safely held in a finely woven mesh that Scryer Prolog provides for me: Because these fundamental building blocks work so reliably, I was able to improve library(format) in ways I originally did not think were possible. With all the latest improvements, the example code above is automatically expanded to:
Note that neither the format string nor the argument list still occur in the resulting code! They have become enmeshed in a list of "instructions" that can be interpreted more efficiently.
Higher-order programming with library(lambda) is another well-known set of constructs that mesh perfectly with the existing meta_predicate/1 directive and other Prolog features.
In the face of such possibilities, I also feel that we have seen nothing yet of what is even possible with Prolog! The efficient string representation of Scryer will make applications possible that nobody thought possible, and today @aarroyocannounced the first Scryer Prolog predicate compiled to native code with cranelift, which was first mentioned a few years ago by @KellerFuchs in #14 (comment). @KellerFuchs, if you are still interested in this, could you please take a look? I would greatly appreciate your help in this area, especially considering the prospect of a natively compiled CLP(B) or CLP(ℤ) on the horizon.
Thank you all for these awesome developments! All these contributions and interactions are themselves like a fine mesh.
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,
in the past few days, I tried to improve the speed of
format_//2
and related constructs.format_//2
is a DCG nonterminal, and often invoked as part of an argument tophrase/2
. For instance, as already mentioned in #2364, it occurs in one of my programs as:In addition, there is also a predicate
format/2
, which is defined in terms of another, more general predicate calledformat/3
:And
format/3
in turn is defined in terms offormat_//2
, wrapped in yet another meta-predicate calledphrase_to_stream/2
fromlibrary(pio)
:It came as a surprise to me that 3 straight-forward clauses of
goal_expansion/2
suffice to improve the running time of each of these constructs in all contexts in which they can arise, even when they are "nested" in completely different constructs as in the examples above, whereformat_//2
occurs as a direct argument ofphrase_to_stream/2
and(',')//2
, and as an indirect argument ofphrase/2
.For instance,
library(format)
can, and per #2363 also does, instruct Scryer Prolog to expand every occurrence of a call toformat/3
in every application program or library directly to its definition, by defining:In the resulting expansion,
format_//2
is used as an argument tophrase_to_stream/2
. I originally thought that any further automated expansion of such an occurrence offormat_//2
as an argument tophrase_to_stream/2
in particular would have to be handled as a special case, in addition to cases where it occurs as a direct or indirect argument ofphrase/2
. However, it turns out that I did not have to do anything special, becausephrase_to_stream/2
is declared as a meta-predicate in such a way that Scryer Prolog knows that its first argument is a goal and hence automatically applies goal expansion to this argument even correctly taking into account the additional declared arguments:I thus feel safely held in a finely woven mesh that Scryer Prolog provides for me: Because these fundamental building blocks work so reliably, I was able to improve
library(format)
in ways I originally did not think were possible. With all the latest improvements, the example code above is automatically expanded to:Note that neither the format string nor the argument list still occur in the resulting code! They have become enmeshed in a list of "instructions" that can be interpreted more efficiently.
Higher-order programming with
library(lambda)
is another well-known set of constructs that mesh perfectly with the existingmeta_predicate/1
directive and other Prolog features.In the face of such possibilities, I also feel that we have seen nothing yet of what is even possible with Prolog! The efficient string representation of Scryer will make applications possible that nobody thought possible, and today @aarroyoc announced the first Scryer Prolog predicate compiled to native code with cranelift, which was first mentioned a few years ago by @KellerFuchs in #14 (comment). @KellerFuchs, if you are still interested in this, could you please take a look? I would greatly appreciate your help in this area, especially considering the prospect of a natively compiled CLP(B) or CLP(ℤ) on the horizon.
Thank you all for these awesome developments! All these contributions and interactions are themselves like a fine mesh.
All the best,
Markus
Beta Was this translation helpful? Give feedback.
All reactions