2011-09-21 5 views
1

다른 문제가 있습니다 : 일부 단어가있는 목록이 있습니다. 단어의 길이가 주어진 길이 (예 : 4)보다 길면 다른 목록에 넣습니다.Sicstus Prolog - 목록에 단어 넣기

내가 시도 :

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)). 

결과는 내가 가지고 :

| ?- Words=["ABCD", "ABCDE", "AAA"], require_min_weight(Words, 5, Lists).  
! Resource error: insufficient memory. 

권리 결과는 다음과 같습니다

Lists = [[65, 66, 67, 68, 69]]. (% ascii) 

어떻게 코드를 변경? 어떤 도움 pls! 감사.

답변

1

조건부에 문제가 있으면 잘못 추가하는 것입니다.

append (Word, List, List)를 사용 중이며 Word가 빈 목록 인 경우에만 성공합니다. 또한 출력 목록에 단어의 코드를 추가하고 싶지는 않지만 단어 자체를 추가하고 싶습니다.

require_min_length([], _, []). 
require_min_length([Word|Words], Minl, NList):- 
    word_length(Word, W), % method word_length return the length of a word. 
    (W >= Minl -> NList=[Word|List] ; NList=List), 
    require_min_length(Words, Minl, List)). 
:

는 다음과 같이 고려