Re: strange error
- Posted by Larry D Poos <ldpoos at JUNO.COM> Jun 28, 1997
- 725 views
On Sat, 28 Jun 1997 03:26:56 -0500 James Powell <wizard at DJO.COM> writes about: Subject: strange error >I've come across a small error in a program I am writing. I am trying >to scan an incomming buffer for known characters, and came up with the >following code: >Attempt to redifine iBufPos > FoundAt = find(iBuffer[iBufPos], Chars) > ^ >From the Library.Doc about find(x,s) Description: Find x as an element of s. If successful, return the index of the first element of s that matches. If unsuccessful return 0. You could also say Find x in s where x is a member of the sequence s. Your code is trying to find s in x. Rewrite as FoundAT=find(Chars,iBuffer). FoundAt will contain the position of Chars if found and 0 if not. If iBuffer is a sequence of sequences then you will have to step though it recursively to locate the Chars variable. Here is a short example of how Find works. It is not written in tight code the hope of showing how find(x,s) works. I am just a beginner with Euphoria so I hope I this is clear enough. Larry D. Poos -[USMC (Retar{bks}{bks}ired) Havelock, NC]- - Programming and System Consultant, LTAD Enterprises - e-mail: ldpoos at juno.com Fido: 1:3629/101.6 ---------------- Begin plain text code segment ------------ with trace -- initialize testing variables sequence iBuffer object FoundAt, SearchFor,tempbuf SearchFor=3 -- you can change this number to any number 10 or less iBuffer={} -- build some data sequences for x=1 to 10 do tempbuf={} iBuffer=append(iBuffer,{x}) for y=7 to 10 do tempbuf=append(tempbuf,rand(y)) end for iBuffer[x]=append(iBuffer[x],tempbuf) end for -- show what we are searching ?iBuffer puts(1,"\n") -- the meat of the search trace(1) -- watch how it works for x=1 to length(iBuffer) do -- loop through each segment for y=1 to length(iBuffer[x]) do -- loop through the subsegments tempbuf=iBuffer[x][y] -- temp storage for what we are going to test if atom(tempbuf) then -- ensure test item is a sequence tempbuf={tempbuf} end if FoundAt=find(SearchFor,tempbuf) -- look for test item if FoundAt then -- display search results printf(1,"%g Found in iBuffer[%d][%d] at position %d\n", {SearchFor,x,y,FoundAt}) else printf(1,"Item not Found in iBuffer[%d][%d]\n",{x,y}) end if end for end for ---------------- End plain text code segment ------------