wysiib / plspec Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Recursive specs (as e.g. one_of) might not trigger a "spec not found" exception if, you guessed it, the spec was not found.
spec_predicate_recursive
: not really recursive from a user perspectiveaux
from the auxiliar predicatesspec_and
and and
or
and or2
Hello,
I noticed plspec and am trying to get my head around using it in my prolog program. I am in particular interested in creating custom types, such as a custom type for an Internal ID and a custom type for a human readable label-- both are atoms.
Can this be done? If yes, are there examples?
thank you,
Dan
Consider the following spec:
:- defspec(tree(X), one_of([compound(node(tree(X), X, tree(X))),
atom(empty)])).
Now if you call valid(X, node(empty, 1, empty))
, you want to get as results for X:
tree(int)
, tree(atomic)
, tree(integer)
and tree(number)
,
But at the moment you also get results like
compound(node(tree(int), int, tree(int))
, compound(node(atom(empty), integer, atomic))
and other combinations.
For node(node(empty,1,empty), 1, node(empty,1,empty))
you get over 40000 results instead of the 4 desired.
It would be great to recognize these recursive structures and stop there.
Either term expansion magic or explicitly stating the module in all calls to plspec.
Consider this code snippet:
generate(true, true, X) :- (...).
generate(false, true, X) :- (...).
generate(true, false, X) :- (...).
A valid spec might be:
:- defspec(boolean, one_of([compound(true), compound(false)])).
:- spec_pre(generate/2, [boolean, boolean, var]).
However, one still does not associate a meaning with these parameters (what is true or false?).
Thus, in order to improve the documentation aspect of plspec, it would make sense to allow (or enforce?) additional syntax in order to name parameters, e.g.:
:- spec_pre(generate/2, [should_do_foo:boolean, should_do_bar:boolean, result:var]).
pls fix
A proper error message should include:
Consider the following (spec'd) predicate:
:- spec_post(my_member/2, [list(X), var], [list(X), X]).
my_member([H|_], H).
Then, assume the query my_member([1,2,3],X).
Expected behaviour: the post condition is selected to be checked later on.
Actual behaviour: the unification of H
in my_member
happens before the which_posts
check occurs, therefore H
is not bound to the variable X
but rather to the value 1
. Thus, the post condition is discarded.
Suggested fix: switch ordering of which_posts
and the unification with the head of the clause if possible. This has to modify the term expander.
Allow to register an error handler that is used instead of throw(_). This should allow to report multiple spec violations in the same run.
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.