Compare commits
5 Commits
v0.1.9-rc.
...
v0.1.9-rc.
Author | SHA1 | Date | |
---|---|---|---|
c1e75afb71
|
|||
20112317fd
|
|||
6015b225a2
|
|||
d3e160222a
|
|||
8110195d62
|
@@ -1,6 +1,6 @@
|
||||
# Change Log
|
||||
|
||||
## (unreleased)
|
||||
## 0.1.9 RC 5 (2018-04-22)
|
||||
|
||||
### Features
|
||||
|
||||
|
@@ -72,7 +72,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (version)
|
||||
{
|
||||
std::cout << "anthem version 0.1.8+git" << std::endl;
|
||||
std::cout << "anthem version 0.1.9-rc.5" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
2
examples/choice-rules.lp
Normal file
2
examples/choice-rules.lp
Normal file
@@ -0,0 +1,2 @@
|
||||
p(a).
|
||||
{q(a)}.
|
@@ -1,10 +1,18 @@
|
||||
#external color(1).
|
||||
#external edge(2).
|
||||
#external vertex(1).
|
||||
#show color/2.
|
||||
|
||||
% assign a set of colors to each vertex
|
||||
{color(V, C)} :- vertex(V), color(C).
|
||||
|
||||
% at most one color per vertex
|
||||
:- color(V, C1), color(V, C2), C1 != C2.
|
||||
|
||||
% at least one color per vertex
|
||||
covered(V) :- color(V, _).
|
||||
:- vertex(V), not covered(V).
|
||||
|
||||
% adjacent vertices don’t share the same color
|
||||
:- color(V1, C), color(V2, C), edge(V1, V2).
|
||||
:- color(V, C1), color(V, C2), C1 != C2.
|
||||
|
||||
#show color/2.
|
||||
|
||||
#external vertex(1).
|
||||
#external edge(2).
|
||||
#external color(1).
|
||||
|
11
examples/letters.lp
Normal file
11
examples/letters.lp
Normal file
@@ -0,0 +1,11 @@
|
||||
letter(a).
|
||||
letter(b).
|
||||
letter(c).
|
||||
|
||||
{p(1..3, Y)} :- letter(Y).
|
||||
:- p(X1, Y), p(X2, Y), X1 != X2.
|
||||
|
||||
q(X) :- p(X, _).
|
||||
:- X = 1..3, not q(X).
|
||||
|
||||
#show p/2.
|
@@ -1,5 +1,4 @@
|
||||
#show p/2.
|
||||
%#external integer(n(0)).
|
||||
|
||||
{p(1..n, 1..n)}.
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#show prime/1.
|
||||
%#external integer(n(0)).
|
||||
|
||||
composite(I * J) :- I = 2..n, J = 2..n.
|
||||
prime(N) :- N = 2..n, not composite(N).
|
||||
|
||||
#show prime/1.
|
||||
|
@@ -1,9 +1,7 @@
|
||||
#show in/2.
|
||||
%#external integer(n(0)).
|
||||
%#external integer(r(0)).
|
||||
|
||||
{in(1..n, 1..r)}.
|
||||
covered(I) :- in(I, S).
|
||||
|
||||
:- I = 1..n, not covered(I).
|
||||
:- in(I, S), in(J, S), in(I + J, S).
|
||||
|
||||
#show in/2.
|
||||
|
9
examples/simple-external-show.lp
Normal file
9
examples/simple-external-show.lp
Normal file
@@ -0,0 +1,9 @@
|
||||
s(X) :- p(X).
|
||||
s(X) :- q(X).
|
||||
u(X) :- r(X), not s(X).
|
||||
|
||||
#show u/1.
|
||||
|
||||
#external p(1).
|
||||
#external q(1).
|
||||
#external r(1).
|
5
examples/simple-external.lp
Normal file
5
examples/simple-external.lp
Normal file
@@ -0,0 +1,5 @@
|
||||
s(X) :- p(X).
|
||||
s(X) :- q(X).
|
||||
|
||||
#external p(1).
|
||||
#external q(1).
|
@@ -13,6 +13,7 @@ namespace anthem
|
||||
constexpr const auto HeadVariablePrefix = "V";
|
||||
constexpr const auto BodyVariablePrefix = "X";
|
||||
constexpr const auto UserVariablePrefix = "U";
|
||||
constexpr const auto IntegerVariablePrefix = "N";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@@ -35,6 +35,7 @@ struct PrintContext
|
||||
std::map<const VariableDeclaration *, size_t> userVariableIDs;
|
||||
std::map<const VariableDeclaration *, size_t> headVariableIDs;
|
||||
std::map<const VariableDeclaration *, size_t> bodyVariableIDs;
|
||||
std::map<const VariableDeclaration *, size_t> integerVariableIDs;
|
||||
|
||||
const Context &context;
|
||||
};
|
||||
@@ -322,22 +323,6 @@ inline output::ColorStream &print(output::ColorStream &stream, const Variable &v
|
||||
|
||||
inline output::ColorStream &print(output::ColorStream &stream, const VariableDeclaration &variableDeclaration, PrintContext &printContext, bool)
|
||||
{
|
||||
const auto domainSuffix =
|
||||
[&variableDeclaration]()
|
||||
{
|
||||
switch (variableDeclaration.domain)
|
||||
{
|
||||
case Domain::Unknown:
|
||||
return "";
|
||||
case Domain::Noninteger:
|
||||
return "n";
|
||||
case Domain::Integer:
|
||||
return "i";
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
const auto printVariableDeclaration =
|
||||
[&](const auto *prefix, auto &variableIDs) -> output::ColorStream &
|
||||
{
|
||||
@@ -350,11 +335,14 @@ inline output::ColorStream &print(output::ColorStream &stream, const VariableDec
|
||||
matchingVariableID = emplaceResult.first;
|
||||
}
|
||||
|
||||
const auto variableName = std::string(prefix) + std::to_string(matchingVariableID->second) + domainSuffix();
|
||||
const auto variableName = std::string(prefix) + std::to_string(matchingVariableID->second);
|
||||
|
||||
return (stream << output::Variable(variableName.c_str()));
|
||||
};
|
||||
|
||||
if (variableDeclaration.domain == Domain::Integer)
|
||||
return printVariableDeclaration(IntegerVariablePrefix, printContext.integerVariableIDs);
|
||||
|
||||
switch (variableDeclaration.type)
|
||||
{
|
||||
case VariableDeclaration::Type::UserDefined:
|
||||
|
@@ -155,7 +155,7 @@ void translate(const char *fileName, std::istream &stream, Context &context)
|
||||
<< "(" << predicateDeclaration->name
|
||||
<< "/" << output::Number(predicateDeclaration->arity())
|
||||
<< "@" << output::Number(i + 1)
|
||||
<< ")." << std::endl;
|
||||
<< ")" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user