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

[REBOL] Re: Stupid question from a newbie

From: greggirwin::mindspring::com at: 20-Feb-2006 10:02

Hi Timothy, TC> I have this little bit of code : TC> mailbox: read pop://XXX:XXXXX-mail.XXX.net TC> ctr: 0 TC> foreach message mailbox [ TC> print pick mailbox ctr TC> wait 0:00:5 TC> remove at mailbox ctr TC> ctr: ctr + 1 TC> ] TC> It seems to work perfectly happily, however it always skips the first TC> message. How do I make it read the first message in the list? You're kind of mixing your metaphors there. The READ call will return a block of messages (see also: IMPORT-MESSAGE), and FOREACH will iterate through that block; so you don't need to use PICK to get a message from the block ('message already references it), but it's not changing the offset of 'mailbox. Also, keep in mind that REBOL series are one-based, not zero-based. Try this to see what's happening: block: [] repeat i 30 [append block i] ctr: 0 foreach val block [ print [ctr pick block ctr] remove at block ctr ctr: ctr + 1 ] print mold block If you want to remove messages from a POP mailbox, you should use OPEN on the mailbox, so it's a port you can work against, then close it when you're done. The first thing I would suggest is to play around with some plain old loop and series ops in the console. Look at how FOREACH, FORALL, FORSKIP, etc. work. Practice iterating over series using WHILE and NEXT, using REPEAT with path notation to access values (e.g. repeat i length? block [print block/:i]). The concepts of series access and navigation by index (PICK, POKE, series/n), ordinal (FIRST, SECOND, etc.), and position (NEXT, BACK, SKIP, AT), are very important. Take some time to understand them and it will pay big rewards. HTH! -- Gregg