Re: Ann: delay pack
Ian Tegebo <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAFBOwCZYuuxMn2=KmneWyATK-SGSxaS7RKqveCE=Nxus301HFA@mail.gmail.com> |
Wow. I find it surprising that delay/1 didn't already exist. Could someone more experienced comment as to previous approaches? A minor suggestion, could you document how to support other predicates? The code is clear enough that I can almost figure it out, but a little help would be nice. Thanks for sharing that. On Fri, Aug 9, 2013 at 10:25 AM, Michael Hendricks <[email protected]> wrote: > 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 > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog -- Ian Tegebo