Search the web
Sign In
New User? Sign Up
win32forth
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Whats the difference between scan and skip   Message List  
Reply | Forward Message #14370 of 14480 |
Re: [win32forth] Whats the difference between scan and skip



> --- On Wed, 7/8/09, P G <psg0912@...> wrote:
>
>
> From: P G <psg0912@...>
> Subject: [win32forth] Whats the difference between scan and skip
> To: "win32 forth" <win32forth@yahoogroups.com>
> Date: Wednesday, July 8, 2009, 7:51 AM
>
>
> Hi,
>
> I typed in the following and --> shows what I get. Scan does what I expect,
but skip seems to do nothing. What does skip do ?
>
> (1) s" 23 45 12" 32 scan type --> 45 12 ok
>
> (2) s" good morning" 109 scan type --> morning ok
>
> (3) cr s" good morning" .s cr 109 skip .s cr
> -->[2] 1519524 12
> --> [2] 1519524 12
> ok..
> (4) cr s" 100 200 300 707" .s cr 55 skip .s cr
> --> [2] 1519784 15
> --> [2] 1519784 15
> ok..
> cr s" 100 200 300 707" .s cr 55 scan .s cr
> --> [4] 1519784 15 1520044 15
> --> [4] 1519784 15 1520056 3
> ok....
>
> Prad.
>

skip ( addr len char -- ) will skip all characters that match with char
and then stop. Your example does nothing because the first character
is not 109 (m), so it doesn't skip anything.

Scan and skip are helpful string parsing primatives. They're not standard
but nearly every Forth system has them. Personally, I find them very
useful in text processing. Things like:

: word[] ( str len n -- str len )
0 ?do bl scan bl skip loop 2dup bl scan nip - ;

make csv and other parsing easier

s" This is a test" 0 word[] type --> This
s" This is a test" 3 word[] type --> test


I don't know why they're not part of the standard. Perhaps there is a
better way to work with strings that I don't know of?

- Tom Dixon








Wed Jul 8, 2009 4:02 pm

phenomenaltom
Offline Offline
Send Email Send Email

Forward
Message #14370 of 14480 |
Expand Messages Author Sort by Date

Hi,   I typed in the following and --> shows what I get. Scan does what I expect, but skip seems to do nothing. What does skip do ?    (1) s" 23 45 12" 32...
P G
psg0912
Offline Send Email
Jul 8, 2009
1:51 pm

... skip ( addr len char -- ) will skip all characters that match with char and then stop. Your example does nothing because the first character is not 109...
Thomas Dixon
phenomenaltom
Offline Send Email
Jul 8, 2009
4:02 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help