2011-11-06 63 views
2

我越來越缺少病例定義,當我調用這個缺失情況下的定義在Miranda

check c (n:nx) state (l:ls,r:rs) 
=true,if((isprefix state c)&(r=n)) 
=false, otherwise 

我檢查了這一點,它可以在自己的不管是什麼我送它。

這是我從調用它(警告:這是一個有點寫的不好現在):

readword input state tape 
=output tape, if (((haltcheck sWord sNum state tape)=true)&(isprefix " halt" rline)) 
=doinst rline state tape , if ((check sWord sNum state tape)=true) 
=readword tail state tape, otherwise 
    where 
    theline = dropwhile notit input 
    start = dropwhile isspace theline 
    sWord = takewhile letter start 
    ends = dropwhile notspace start 
    distart = dropwhile isspace ends 
    sNum = takewhile notspace distart 
    tail = dropwhile notspace distart 
    rline = takewhile notit tail 

回答

2

缺少的情況下的定義是指你的模式匹配,你不覆蓋所有病例。這會在您的check函數的定義中發生兩次:您將第二個參數與n:nx模式匹配,但不匹配[]模式(因此您沒有覆蓋第二個參數可能爲空列表的情況)。同樣,你也可以將第四個參數與(l:ls, r:rs)相匹配,而不是說明這個對的任何一個元素可能是空列表。

所以發生了什麼導致錯誤是,當你從readword調用check要麼sNum爲空或tape的列表中的一個是空的。

+0

非常感謝你,沒想到現在是在踢我自己。 – user23012

相關問題