From 10a679925681d911eb6700ec4ec2608a941457dd Mon Sep 17 00:00:00 2001 From: Roland Kaminski Date: Fri, 23 Jun 2023 12:29:15 +0200 Subject: [PATCH] fix add_theory_term_sequence --- libclingo/clingo.h | 6 +++--- libclingo/src/control.cc | 2 +- libpyclingo/clingo/tests/test_backend.py | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libclingo/clingo.h b/libclingo/clingo.h index e4a6556e..331ea886 100644 --- a/libclingo/clingo.h +++ b/libclingo/clingo.h @@ -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; diff --git a/libclingo/src/control.cc b/libclingo/src/control.cc index 75e3bc01..0c93c50e 100644 --- a/libclingo/src/control.cc +++ b/libclingo/src/control.cc @@ -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(type)}, Potassco::IdSpan{arguments, size}); + *term_id = backend->theoryData().addTermTup(Potassco::Tuple_t{-static_cast(type) - 1}, Potassco::IdSpan{arguments, size}); } GRINGO_CLINGO_CATCH; } diff --git a/libpyclingo/clingo/tests/test_backend.py b/libpyclingo/clingo/tests/test_backend.py index 60a5de92..e0ebb0e0 100644 --- a/libpyclingo/clingo/tests/test_backend.py +++ b/libpyclingo/clingo/tests/test_backend.py @@ -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)) @@ -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, []) @@ -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])