From 7ddbe59588b3fd34fa9efc39ab56055f925d29ac Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Tue, 8 Mar 2016 23:40:13 +0100 Subject: Hints for memb/2 added. --- prolog/problems/lists/memb_2/common.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'prolog/problems/lists/memb_2/common.py') diff --git a/prolog/problems/lists/memb_2/common.py b/prolog/problems/lists/memb_2/common.py index 9ac56f6..e04535a 100644 --- a/prolog/problems/lists/memb_2/common.py +++ b/prolog/problems/lists/memb_2/common.py @@ -22,6 +22,8 @@ hint_type = { 'eq_instead_of_equ_markup': HintPopup('eq_instead_of_equ_markup'), 'eq_instead_of_equ': Hint('eq_instead_of_equ'), 'predicate_always_false': Hint('predicate_always_false'), + 'base_case': Hint('base_case'), + 'timeout': Hint('timeout'), 'final_hint': Hint('final_hint'), } @@ -59,21 +61,29 @@ def hint(code, aux_code): try: engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) - # gender testing is redundant - # this is not necessarily wrong, but worth mentioning anyway + # strict equality testing instead of simple matching + # this is usually (but not necessarily) wrong targets = [prolog.util.Token('EQ', '==')] marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] if marks: return [{'id': 'eq_instead_of_equ_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ [{'id': 'eq_instead_of_equ'}] + # recursion is getting bigger and bigger + + # target predicate seems to always be false - if not prolog.engine.ask_truth(engine_id, 'grandparent(_, _)'): + if not prolog.engine.ask_truthTO(engine_id, 'memb(_, _)'): return [{'id': 'predicate_always_false'}] + # missing/failed base case + if not prolog.engine.ask_truthTO(engine_id, 'memb(qq, [qq|_])'): + return [{'id': 'base_case'}] + + # TODO: Tim, can we include 'fail'-used as a general hint? except socket.timeout as ex: - pass + return [{'id': 'timeout'}] finally: if engine_id: -- cgit v1.2.1