:- use_module(library(sweet)). ?- (false -> throw(oops); otherwise -> writeln(ok)). ok true. ?- if(fail,throw(oops)), if(true,writeln(ok)). ok true. ?- forall(X in [1,2,3], writeln(ok)). ok ok ok true. :- use lists -> append/{2,3}, last/2. % same as use_module(library(lists),[append/2,append/3,last/2]).
The sweet
pack adds some convenient syntactic sugar to Prolog. The
main goal is to reduce the amount of redundant code that one must read
(and write). Some of the predicates and macros are simple aesthetic
adjustments (like otherwise/0). Others, like in/2, define powerful
interfaces which can be extended by library authors.
Using SWI-Prolog 6.3 or later:
?- pack_install(sweet).
This module uses semantic versioning.
Source code available and pull requests accepted at http://github.com/mndrix/sweet
sweet.pl | ||
---|---|---|
cleanup/1 | Sugar for call_cleanup/2. | |
if/2 | Same as (Condition->Action;true) . | |
if/3 | Same as (Condition->Action;Else) . | |
in/2 | True if X is contained in Xs. | |
otherwise/0 | AKA true . | |
todo/0 | Throws the exception todo . | |
todo/1 | Like todo/0 with a Note. | |
todo/2 | Like todo/1 but provides space for something Extra. | |
use/1 | Macros for importing modules. |