@sculptor: I cannot reproduce your issue. Here is the sample code I used with the line that contains ResetList() commented out:
Code: Select all
EnableExplicit
Global NewList dict_contents.s()
Define h, i, j, k
#ASCII_A = 'A'
#ASCII_Z = 'Z'
;fill list with 456976 4 letter words "AAAA" through "ZZZZ"
For h = #ASCII_A To #ASCII_Z
For i = #ASCII_A To #ASCII_Z
For j = #ASCII_A To #ASCII_Z
For k = #ASCII_A To #ASCII_Z
AddElement(dict_contents())
dict_contents() = Chr(h) + Chr(i) + Chr(j) + Chr(k)
Next
Next
Next
Next
Procedure.i find_the_word(word.s);word is passed from a different list, foreach
Protected tmp.i = 0
ForEach dict_contents() ;loop thru a global dictionary of words (i would have thought the foreach would set back to element 0)
tmp.i + 1
If dict_contents() = word.s ;is the word in the dict?
Debug tmp.i ; here on the second call to the procedure list element has been remembered
;ResetList(dict_contents()) ; so unless i do this reset i have the wrong count in tmp
ProcedureReturn tmp.i
EndIf
Next
Debug "tmp here is= " + tmp
ProcedureReturn 0
EndProcedure
Define a$
Repeat
;generate random 4 letter word
a$ = Chr(Random(#ASCII_Z, #ASCII_A)) +
Chr(Random(#ASCII_Z, #ASCII_A)) +
Chr(Random(#ASCII_Z, #ASCII_A)) +
Chr(Random(#ASCII_Z, #ASCII_A))
Debug a$
Debug "---result of search 1: " + find_the_word(a$)
Debug "---result of search 2: " + find_the_word(a$)
Debug "---result of search 3: " + find_the_word(a$)
a$ = InputRequester("", "Press Enter to repeat, Q to quit.", "")
Until a$ = "Q" Or a$ = "q"
The test code creates a list of 456976 unique words. If a previous list position was used in the procedure than it would never find the word in additional searches. It produces consistent results as is.
The lines you have documented with "here on the second call to the procedure list element has been remembered", will only be reached if a match is found and so will always contain the same element out of a set of unique elements. Your conclusion that this is somehow evidence of buggy behavior is incorrect.