I try to build predicate which will append random number of sublists result list.
my_predicate([], AnotherList, []).
my_predicate([Head|List], AnotherList, Result):-
random(0,5,N),
nested_predicate(N, Head, AnotherList, SM),
my_predicate(List, AnotherList, Result),
append(SM, Result, SM2),
write(SM2).
And everything nearly ok, but I cannot assign SM2 to Result in any way. What I’m doing so wrong?
In Prolog, you cannot “assign” a value to a variable. Also, in your code,
Resultwill always be bound to an empty list.I assume what you want is something like this: