Ann: delay pack
Michael Hendricks <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAFHuXuZjFsBgM=ycP2ELEwdH3=-jZo=8hFxw16NPkLgR8zYTWA@mail.gmail.com> |
I've just released a pack which helps avoid instantiation errors with built-in predicates. By using delay/1 a single clause can operate in many modes without manually re-ordering goals. You can read the full documentation <http://www.swi-prolog.org/pack/list?p=delay> for details. Here's a quick demo: ?- delay(succ(A,B)), A=1. A = 1, B = 2. ?- delay(plus(A,3,C)), C=5. A = 2, C = 5. ?- delay(univ(T,Name,Args)), Name=hello, Args=[world]. T = hello(world), Name = hello, Args = [world]. I finally got tired enough of writing the same when/2 goals over and over that I figured it was time for a library. I find this style especially helpful with DCGs where it allows predicates to both generate and parse content with a single definition. As always, feedback, criticism and pull requests are welcome. -- Michael -------------- next part -------------- HTML attachment scrubbed and removed