ℙ𝕖𝕡 🙴 ℕ𝕠𝕞

home | documentation | examples | translators | download | blog | all blog posts

I'm never bored by simplicity. Charles Moore (Forth inventor)

the ℕ𝕠𝕞 "whilenot" command

The whilenot command reads into the workspace buffer characters from the input stream while the peep buffer is not a certain character or characters. This is a “tokenizing” or “lexing” command and allows the input stream to be parsed up to a certain character without reading that character.

The whilenot command does not exit if it reaches the end of the input-stream (unlike the read command).

print one word per line
 r; [:space:] { d; } whilenot [:space:]; add "\n"; print; clear;

another way to print one word per line
 r; [ ] { while [ ]; clear; add "\n"; } print; clear;

The advantage of the first example is that it allows the script to tokenise the input stream into words

notes

The whilenot command cannot automatically ignore escaped characters like until does.

a trap when parsing text with while


    read;
    "'" { 
      # be aware that whilenot will stop at \\' and so
      # may not parse the whole profound utterance.
      whilenot "'"; put; clear;
      add "profound.utterance*";
      push; .reparse
    }
  

The while, whilenot and until commands will not exit to the operating system when they encounter the end-of-file or end-of-stream. This contrasts with the behavior of read , which will exit the script loop.

It is possible that the until command should also be able to take a class argument so that multiple characters could be used as an stop-condition for until.

see also

The following are all commands that read the input-stream.