summaryrefslogtreecommitdiff
path: root/prolog/problems/lists/memb_2/common.py
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-08 23:40:13 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-08 23:40:13 +0100
commit7ddbe59588b3fd34fa9efc39ab56055f925d29ac (patch)
tree48292cd307a185b8a1be723a24578777fd343f28 /prolog/problems/lists/memb_2/common.py
parent16a5005880a75537ba7450d07512d27cca05fbf3 (diff)
Hints for memb/2 added.
Diffstat (limited to 'prolog/problems/lists/memb_2/common.py')
-rw-r--r--prolog/problems/lists/memb_2/common.py18
1 files changed, 14 insertions, 4 deletions
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: