3 ms·
>> As I said, in Prolog you cannot nest loops. You cannot nest loops. What do you mean here? My earlier comment was jokular, but you can definitely nest loops
by YeGoblynQueenne 9y ago
>> As I said, in Prolog you cannot nest loops. You cannot nest loops.
What do you mean here? My earlier comment was jokular, but you can definitely nest loops in Prolog:
...
deconstruct([L|Ls],Acc1,Bind):-
deconstruct(L,Acc1,Acc2)
,deconstruct(LS,Acc2,Bind).
...
etc. That's a nested loop, right there.
Do you mean it in the sense that it's still the same predicate rather than a consecutive change of scopes?
- tom_mellior 9y agoMost concretely I mean it in the context of the common auxiliary-predicate-with-an-accumulator pattern: foo_bar(Foo, Bar) :- foo_bar_aux(Foo, Bar, 0). foo_bar_aux(Foo, Bar, N) :- ... Which in a language like OCaml would be hiding the loop in a recursive function defined inside the main one: let foo_bar foo = let rec foo_bar_aux n = ... in foo_bar_aux 0 So yes, I think this is what you mean by being the same predicate rather than a "change of scopes". Of course there are many loop-like things that you can nest. If the arguments align just right, you can also use `maplist(maplist(maplist(baz)), ...)` instead of three auxiliary predicates, but I don't encounter many cases where this is possible or desirable.
- YeGoblynQueenne 9y agoI see what you mean, thanks. I think we're talking about the same thing then.