From d259285459176fc281193adb12483a6e6d527cf5 Mon Sep 17 00:00:00 2001
From: Aleksander Sadikov LenT + 1
.
If I take away the head, and the recursion solves this smaller problem (tail), and if I add 1 to the -result returned by the recursion, then I got the length of the whole list.
+result returned by the recursion, then I get the length of the whole list. '''] hint = { 'eq_instead_of_equ': '''\The operator ==
is "stricter" than operator =
in the sense that
for the latter it is enough to be able to make the two operands equal (unification). Perhaps by using =
-you can make the predicate conc/3
more general (e.g. able to work with output arguments becoming inputs).
len/2
more general (e.g. able to work with output arguments becoming inputs).
Of course, you can also solve the exercise without explicit use of either of these two operators, just remember that unification is implicitly performed with the predicate's arguments (head of clause).
''', @@ -78,7 +78,7 @@ second operand and only then attempts the unification of both operands. 'forcing_result_onto_recursion': '''Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job. If this assumption is correct, then the rule will work for a larger case.
-Is your recursive call of the form len(T, LenT + 1)
? This forces the recursive call to
+
Is your recursive call of the form len(Tail, LenTail + 1)
? This forces the recursive call to
return the length of the whole list, not just the tail! This will not work. It is your job to
increase by one the result returned by the recursion. In short, add one outside the recursive call.
Ne vsiljuj rekurziji kaj naj vrne, prepusti se ji. To je tisti del, ko narediš predpostavko, če je ta izpolnjena, potem bo tvoje pravilo delovalo za večji primer.
-Je tvoj rekurzivni klic oblike len(T, LenT + 1)
? S tem vsiljuješ rekurziji
-da mora
Je tvoj rekurzivni klic oblike len(Tail, LenTail + 1)
? S tem vsiljuješ rekurziji
+da mora vrniti dolžino celega seznama in ne samo repa. To ni v redu, za ena moraš ti povečati
rezultat, ki ti ga rekurzija vrne. Skratka, prištevanje naredi izven rekurzivnega klica.