Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

Issue with block command 'NEXT'

 [1/2] from: John_Dutcher:URMC:Rochester at: 2-Jul-2003 15:38

Hi, The code fragment below shows promise for deleting a block from a rebol style database file. It finds the block within the database properly and reports that it removed saves the file, and the expected block is gone and the file has compressed itself to close the gap perfectly. BUT....the next iteration of the 'For loop' fails to find a good series to look at, as evidenced by the error msg. also shown below (I let the loop continue in case there are additional blocks meeting the search criteria) ??? As a side item, I was puzzled that my originally coded 'remove pick database i' originally on line (5) didn't work (only removed first value in the block)i, but 'remove next database i' seemed to remove entire block (as was intended). ********************************************************************** Code; remove-data: func [lottery-name ticket-value] [ for i 1 length? database 1 [ if equal? first pick database i lottery-name [ if equal? second pick database i ticket-value [ remove next database i ;This may be working by coincidence, just because it's the 2nd block ? print [" "] print ["Yes, the ticket: " lottery-name " " ticket-value " was removed"] save db-file database ] ;end if ] ;end if ] ;end for ] ;end func *************************************************************************** Error:
>> remove-data lottery-name ticket-value
Yes, the ticket: UK Powerball 99 99 99 99 99 99 was removed ** Script Error: first expected series argument of type: series pair event money date object port time tuple any-function library struct event ** Where: do-body ** Near: if equal? first pick database

 [2/2] from: brett:codeconscious at: 3-Jul-2003 11:06

When you remove something from a block, the block gets shorter. A FOR loop is set for a specific number of iterations - in this case based on the original length of the block. So at some point if you remove something your loop will "fall off" the end - go past the tail. Maybe you should change your code from using FOR to using WHILE. Regards, Brett.