> --- 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