Lazy goal call (a bit of a half baked idea)

Hello,

Is it possible to “schedule” a call to a goal for later, when a certain condition holds …

Suppose that during some processing, say, parsing, pieces of information become available for calling a goal – however, the full information for calling the goal is not completed, and the full information for calling the goal will only become available at the end of the parse.

One way I could do it is to create (say, via global variables) a queue or stack of callable goals with (partial?) parameters (i.e. a closure), that would be explicitly called at a later point in time.

I am curious if there are some “built-in” mechanisms that could be used instead.

A closure, btw, is not in particular necessary – the final piece of information could be an asserted as fact by the parse, and once its available, those “lazy” goals could be called to complete the processing.

That sounds like an accumulator to me, no?

Correct this it is wrong.

The code should parse some input. As the parsing progresses an accumulator accumulates the information needed for another goal after the parse has been completed. The accumulated data can be a compound, list, partial list, string, etc.

1 Like

You can probably do what you want to with coroutining, although it may be overkill.

Does’t phrase/2 gives you just that?

During parsing you can build e.g. a list of goals returned in the phrase/2 second argument and than call all the goals in that list. The individual elements in the list can be callable terms that share variables with the first argument so that the data that’s only available at end of parsing is shared with all the goals.

2 Likes