Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 116,871 of 117,927    |
|    dxf to All    |
|    Number parsing with checks    |
|    12 Oct 24 12:45:10    |
      From: dxforth@gmail.com              The basics:              : .BAD ( -- ) cr ." Invalid item" .abort ;              : ZE? ( x -- ) if .bad then ; \ abort if non-zero       : NZ? ( x -- ) 0= ze? ; \ abort if zero       : ?ZE ( x -- x ) dup ze? ; \ check x is zero       : ?NZ ( x -- x ) dup nz? ; \ check x is non-zero              Examples:              : ?D>S ( d|ud -- n|u ) -1 0 between nz? ;       : ?RNG ( n|u lo hi -- n|u ) rot dup 2swap between nz? ;              \ Single number parsers with checking       : /DNUM ( a u -- a' 0 d|ud )        /sign >r ?nz (number) ?ze 2swap r> if dnegate then ;       : /NUM ( a u -- a' 0 n|u ) /dnum ?d>s ;       : /HEX ( a u -- a' 0 n|u ) base @ >r hex /num r> base ! ;              \ String to unsigned int with checking       : >INT ( a u -- u2 ) ?nz (number) ?ze 2drop ze? ;              where              : (NUMBER) ( a u -- ud a' u' ) 0 0 2swap >number ;              : /SIGN ( a u -- a' u' f )        dup if over c@ dup [char] + = swap [char] - =        dup >r or negate /string r> exit then 0 ;              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca