Skip to content

Commit

Permalink
fix add_theory_term_sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
rkaminsk committed Jun 23, 2023
1 parent 1aaea01 commit 10a6799
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions libclingo/clingo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1510,9 +1510,9 @@ typedef int clingo_comment_type_t;

//! Enumeration of theory sequence types.
enum clingo_theory_sequence_type_e {
clingo_theory_sequence_type_tuple, //!< Theory tuples "(t1,...,tn)".
clingo_theory_sequence_type_list, //!< Theory lists "[t1,...,tn]".
clingo_theory_sequence_type_set //!< Theory sets "{t1,...,tn}".
clingo_theory_sequence_type_tuple = 0, //!< Theory tuples "(t1,...,tn)".
clingo_theory_sequence_type_set = 1, //!< Theory sets "{t1,...,tn}".
clingo_theory_sequence_type_list = 2 //!< Theory lists "[t1,...,tn]".
};
//! Corresponding type to ::clingo_theory_sequence_type_e.
typedef int clingo_theory_sequence_type_t;
Expand Down
2 changes: 1 addition & 1 deletion libclingo/src/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ extern "C" bool clingo_backend_theory_term_symbol(clingo_backend_t *backend, cli

extern "C" bool clingo_backend_theory_term_sequence(clingo_backend_t *backend, clingo_theory_sequence_type_t type, clingo_id_t const *arguments, size_t size, clingo_id_t *term_id) {
GRINGO_CLINGO_TRY {
*term_id = backend->theoryData().addTermTup(Potassco::Tuple_t{-static_cast<int>(type)}, Potassco::IdSpan{arguments, size});
*term_id = backend->theoryData().addTermTup(Potassco::Tuple_t{-static_cast<int>(type) - 1}, Potassco::IdSpan{arguments, size});
}
GRINGO_CLINGO_CATCH;
}
Expand Down
6 changes: 4 additions & 2 deletions libpyclingo/clingo/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def test_adding_theory(self):
seq = backend.add_theory_term_sequence(
TheorySequenceType.Set, [num_one, num_two, str_x]
)
lst = backend.add_theory_term_sequence(TheorySequenceType.List, [num_one, num_two])
tup = backend.add_theory_term_sequence(TheorySequenceType.Tuple, [num_one, num_two])
fseq = backend.add_theory_term_function("f", [seq])

self.assertEqual(num_one, backend.add_theory_term_number(1))
Expand All @@ -255,7 +257,7 @@ def test_adding_theory(self):
fun, backend.add_theory_term_symbol(parse_term("f(1,2,x)"))
)

elem = backend.add_theory_element([num_one, num_two, seq, fun], [1, -2, 3])
elem = backend.add_theory_element([num_one, num_two, seq, fun, lst, tup], [1, -2, 3])

# Tests with guards and elements
backend.add_theory_atom(0, fun, [])
Expand All @@ -272,7 +274,7 @@ def test_adding_theory(self):
"&f(1,2,x){}",
"&f(1,2,x){}=1",
"&g(1,2){}",
"&f({1,2,x}){1,2,{1,2,x},f(1,2,x): #aux(1),not #aux(2),#aux(3)}",
"&f({1,2,x}){1,2,{1,2,x},f(1,2,x),[1,2],(1,2): #aux(1),not #aux(2),#aux(3)}",
],
)
self.assertEqual(atoms[-1].elements[-1].condition, [1, -2, 3])
Expand Down

0 comments on commit 10a6799

Please sign in to comment.