Re: strange error

new topic     » goto parent     » topic index » view thread      » older message » newer message

> 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:
>          for iBufPos = 1 to length(iBuffer)
>  [0;30m            FoundAt = find(iBuffer[iBufPos], Chars)
>  [0;30m            if FoundAt then
>                 DoSomething
>             end if
>          end for
> iBufPos and FoundAt are atoms, and iBuffer and Chars are both sequences.
> My reasoning follows:
>  1. look at each character in iBuffer, and if found in Chars go do
> something.
> However, when I try to run the program I get the following error:
> Attempt to redifine iBufPos
>        FoundAt = find(iBuffer[iBufPos], Chars)
>              ^
> I do not understand how I could be redefining iBufPos.  I am using it as
> a for loop counter, stepping through iBuffer.  I know that I cannot
> asign a new value to iBufPos (and by looking at the code, I don't see
> that happening).  I thought find used the first arguement as the search
> criteria, and the second as the place to search in.  I do not think that
> using the value in iBufPos as a pointer to a single character inside
> iBuffer should be causing a redefinition of iBufPos.
> Any help would be greatly appreciated.

Make sure that you have not previously defined iBufPos with a command
like :

atom iBufPos

Using a for-loop automatically defines a variable for you.

Other than that, your code is correct except that the line:

>          for iBufPos = 1 to length(iBuffer)

should read:

for iBufPos = 1 to length(iBuffer) do

For-loops and while-loops need the word "do" before the actual code
inside the loop.

Regards,
              Michael Bolin

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu