1. ex.exe hangs in a while loop
- Posted by olddog <halletts at sasktel.net> Jul 12, 2006
- 528 views
My 2.5 interpreter hangs (even the trace() debugger hangs) with this code:
incude get.e procedure main() integer crsr, price sequence text, t text = "/GRVY $.75 /GRVY $.75" price = 0 crsr = find('$', text) while crsr do t = value(text[crsr+1..$]) if t[1] = GET_SUCCESS then price += t[2]
2. Re: ex.exe hangs in a while loop
- Posted by olddog <halletts at sasktel.net> Jul 12, 2006
- 497 views
Oops! Punched a wrong button half way thorugh my post: My 2.5 interpreter hangs (even the trace() debugger hangs) with this code:
incude get.e procedure main() integer crsr, price sequence text, t text = "/GRVY $.75 /GRVY $.75" price = 0 crsr = find('$', text) while crsr do t = value(text[crsr+1..$]) if t[1] = GET_SUCCESS then price += t[2]*100 end if crsr = find('$', text[crsr+1..$]) end while end procedure
If text only equals "/GRVY $.75" then it works fine, but as it is above it hangs (the debug trace locks up on the end while statement). Workarounds, anyone? BTW, I am enjoying using this interpreter on an old DOS box!
3. Re: ex.exe hangs in a while loop
- Posted by Derek Parnell <ddparnell at bigpond.com> Jul 12, 2006
- 498 views
olddog wrote: > > Oops! Punched a wrong button half way thorugh my post: > > My 2.5 interpreter hangs (even the trace() debugger hangs) with this code: > > }}} <eucode> > incude get.e > procedure main() > integer crsr, price > sequence text, t > text = "/GRVY $.75 /GRVY $.75" > price = 0 > crsr = find('$', text) > while crsr do > t = value(text[crsr+1..$]) > if t[1] = GET_SUCCESS then > price += t[2]*100 > end if > crsr = find('$', text[crsr+1..$]) > end while > end procedure > </eucode> {{{ > > If text only equals "/GRVY $.75" then it works fine, but as it is above > it hangs (the debug trace locks up on the end while statement). > > Workarounds, anyone? I can see a problem. The second find() gives a result as an offset from the first '$' and you don't adjust that to be an offset from the start of the text. Try this instead... temp = find('$', text[crsr+1..$]) if temp then crsr += temp+1 end if end while The details... On the first find() it returns 7. So the second find() looks at the slice starting at 8 which returns 10. This is the offset from the start of the slice, not the start of the text. To adjust it you need to add the slice start position to the returned value, making it 18. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
4. Re: ex.exe hangs in a while loop
- Posted by don cole <doncole at pacbell.net> Jul 12, 2006
- 508 views
olddog wrote: > > Oops! Punched a wrong button half way thorugh my post: > > My 2.5 interpreter hangs (even the trace() debugger hangs) with this code: > > }}} <eucode> > incude get.e > procedure main() > integer crsr, price > sequence text, t > text = "/GRVY $.75 /GRVY $.75" > price = 0 > crsr = find('$', text) > while crsr do > t = value(text[crsr+1..$]) > if t[1] = GET_SUCCESS then > price += t[2]*100 > end if > crsr = find('$', text[crsr+1..$]) > end while > end procedure > </eucode> {{{ > > If text only equals "/GRVY $.75" then it works fine, but as it is above > it hangs (the debug trace locks up on the end while statement). > > Workarounds, anyone? > > BTW, I am enjoying using this interpreter on an old DOS box! Hello olddog, find() is used to find a sequence in a sequence. Such as crsr=find({"/GRVY $.75","/GRVY $.75"}) to find character in a string (what you are doing) you should use match(). for x=1 to length(text) do crsr=match(text[x..x]) end for Hope this helps. Don Cole
5. Re: ex.exe hangs in a while loop
- Posted by Derek Parnell <ddparnell at bigpond.com> Jul 12, 2006
- 520 views
I meant to suggest that instead of using find() you use the find_from() function below ...
global function find_from(object item, sequence source, integer start) integer pos if start > length(source) then return 0 end if if start < 1 then return 0 end if pos = find(item, source[start..$]) if pos then pos += start - 1 end if return pos end function
Then you could code ... crsr = find_from('$', text, crsr+1) -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
6. Re: ex.exe hangs in a while loop
- Posted by Derek Parnell <ddparnell at bigpond.com> Jul 12, 2006
- 523 views
don cole wrote: > find() is used to find a sequence in a sequence. Such as crsr=find({"/GRVY > $.75","/GRVY > $.75"}) > > to find character in a string (what you are doing) you should use match(). I'm sorry Don, but you've got that the wrong way round. find() is used to locate a single element in a sequence, such as a character in a string. match() is used to locate a set of adjacent items in a sequence, such as a substring within a string. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
7. Re: ex.exe hangs in a while loop
- Posted by Cuvier Christian <christian.cuvier at insee.fr> Jul 12, 2006
- 518 views
Subject: Re: ex.exe hangs in a while loop Oops! Punched a wrong button half way thorugh my post: My 2.5 interpreter hangs (even the trace() debugger hangs) with this code:
include get.e procedure main() integer crsr, price sequence text, t text = "/GRVY $.75 /GRVY $.75" price = 0 crsr = find('$', text) while crsr do t = value(text[crsr+1..$]) if t[1] = GET_SUCCESS then price += t[2]*100 end if crsr = find('$', text[crsr+1..$]) end while end procedure
If text only equals "/GRVY $.75" then it works fine, but as it is above it hangs (the debug trace locks up on the end while statement). Workarounds, anyone? BTW, I am enjoying using this interpreter on an old DOS box! ------------------------------ This is not really a workaround, but setting the program logic right. The line
crsr = find('$', text[crsr+1..$])
should read
text = text[crsr+1..$] crsr = find('$', text)
This works, as it changes the text so that the loop always appears to start from scratch. The problem in the original code is that crsr is the position of the next '$' relative to the previous, but you use it as an absolute index into the unchanged 'text'. And since you compute the tail of text twice, that's one time too many:
include get.e procedure main() integer crsr, price sequence text, t text = "/GRVY $.75 /GRVY $.75" price = 0 crsr = find('$', text) while crsr do text = text[crsr+1..$] t = value(text) if t[1] = GET_SUCCESS then price += t[2]*100 end if crsr = find('$', text) end while end procedure
Also, if you expect value() to fail sometimes, you probably have to add some sort of reporting of such a condition, since price, which will be the sum of all correctly read prices on return, may be inaccurate then. Oh, by the way, how do you retrieve the contents of that private variable? You may need to turn the procedure into a function and add a "return price" statement after the loop ends. Or to make price local rather than private. HTH CChris
8. Re: ex.exe hangs in a while loop
- Posted by olddog <halletts at sasktel.net> Jul 12, 2006
- 525 views
Thanks so much to Derek, Don, and Cuvier for their insights and replies. You guys were absolutely right, I failed to adjust crsr's value properly when doing the second "find()", so "value()" had no chance of succeeding as it was given the wrong parameter. But the problem with adjusting crsr to compensate for this (which could be done as simply as "crsr += find('$', text[crsr+1..$])", is that the loop uses "crsr > 0" as its true/false looping condition. So Derek's code would work fine as long as the loop condition used temp instead of crsr, and so the initial find() would need to be assigned to temp, too. (BTW, this code is actually in a function that needs to return the values of text (intact) and price. I just stuck it in main() in case someone wanted to test the debugger issue--that is, if it is an issue.) So, with thanks to the worldwide debugging team, the corrected code is:
incude get.e procedure main() integer crsr, price, offset sequence text, t text = "/GRVY $.75 /GRVY $.75" price = 0 offset = 0 crsr = find('$', text) while crsr do t = value(text[crsr+offset+1..$]) if t[1] = GET_SUCCESS then price += floor(t[2]*100) -- ensure truncating to an integer end if offset = crsr+1 crsr = find('$', text[offset..$]) end while end procedure
However, I still find it odd that although my failed logic (trying to code at 3 a.m. when I could barely focus on the keyboard) hung the debugger. Shouldn't it just keep stepping me through the loop over and over? Or is that because I was using the down arrow instead of the Enter key? Thanks again, everyone!