Got another problem:
There is a list with some words. If the length of the word is more than a given length (ex. 4), it will be put in an another list.
I tried:
require_min_length([], _, []).
require_min_length([Word|Words], Minl, [List]):-
word_length(Word, W), % method word_length return the length of a word.
(W >= Minl -> append(Word, List, List), require_min_length(Words, Minl, List);
require_min_length(Words, Minl, List)).
Results I got:
| ?- Words=["ABCD", "ABCDE", "AAA"], require_min_weight(Words, 5, Lists).
! Resource error: insufficient memory.
The right result will be:
Lists = [[65, 66, 67, 68, 69]]. (% ascii)
How to change the code? Any help pls! Thanks.
The problem with your predicate is that you are using append wrong.
You are using append(Word, List, List), this would only succeed if Word is an empty list. Also you really don’t want to append the codes of your word to the output list, but the word itself.
Consider something like this: