mndrix / delay Goto Github PK
View Code? Open in Web Editor NEWCoroutine versions of built-in Prolog predicates
License: The Unlicense
Coroutine versions of built-in Prolog predicates
License: The Unlicense
I searched for uses of when/2 in Prolog code on my machine. These predicates would benefit from delay/1 support:
I can probably generalize from those few examples to include other operators (like =:=) and other type checks (like callable).
Jan pointed out
delaying over a cut changes the semantics.
So, if you use this you either should not use cuts or be very
careful with them.
The first improvement is to document this circumstance so that developers are aware of the problem.
It'd also be nice to generate warnings about delay/1
that occur before !/0
in a clause. This doesn't cover all problem scenarios but it should help notice some common ones. If I go this route, there needs to be a way to say, "I know what I'm doing, leave me alone". Ideally, there should be a style_check/1
mode that enables this warning.
The library should provide support for maplist/3, maplist/4, etc. It should also work even if the maplist calls have been expanded via apply_macros.pl
.
We can probably just look for a predicate whose name starts with __aux_maplist
to detect that it's a maplist expansion.
I want users to be able to add delay/1
support to any predicates they care about. Making that happen requires a decent rewrite. As follows:
mode/1
as it's writteng
and n
with ground
and nonvar
, respectivelydelay/1
clause cuts before calling when/2
. otherwise, when/2
can fail because all arguments are ground and the underlying goal fails. that would backtrack to the final delay/1
clause and throw an exception. Be sure to write a failing test for this first, then make changes to make it pass. without a test, I'm sure I'll encounter this same corner case again.delay/1
consult mode/1
to build a when/2
goal then assert it as an additional clause on delay/1
(the assertion is an optimization)delay/1
into meta_predicate delay(0)
and change mode/1
so that each built-in predicate is prefaced with system:
. Look at mode/1
with the module-qualified head. If there's no mode for that, call predicate_property(Head, imported_from(Module))
to determine if this predicate is originally from another module. Perform the mode/1
look up using that module. If there's no mode/1 declaration in either case, throw an error with instructions about how to add support for other predicates.delay_followup/1
always has a nonvar(List)
guard in the list(_)
case:- multifile mode/1.
delay:mode(foo:bar(ground,_))
facts to support additional predicates.SWI-Prolog's SICSTUS compatibility layer includes the block/1
directive which fills a niche similar to delay/1
. Link to it from the documentation and perhaps comment on the differences between each approach. For example, does block/1
work with built-in predicates? Does it work with foreign predicates? Does it work with dynamic predicates? I'm pretty sure that delay/1
works with all of them. I think that delay/1
has a more flexible mode language than block/1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.