factored range checking 
Author Message
 factored range checking

0 [IF] DEMO - FACTORED INDEX RANGE CHECKING
    Michael Gassenenko in his paper _C-Style Indexing in ANS Forth_
  (www.forth.org.ru/mlg/cstyle.htm) presents a nice set of simple
  array words. Without range checking the words are very simple and
  even if range checking is added not much simplicity is lost. However,
  a high degree of simplicity and flexibility can be maintained if
  the range checking is kept factored out and provided in a word that can
  be inserted when desired.
    In this demo _? is the factored index range checking. When range
  checking is desired it can be inserted before the array word [] .
  For demo purpose _? on range error will print a message and refill.
  For real operations it can be made to throw or abort.
    To support _? the array is structured to contain the column size of
  each column and the number of rows. If the array needs to be constructed
  without storing the column sizes (as done in MLG's example) then other
  ways of defining _? using []LEN can be done but won't apply in the
  same manner as in this example.
    One last note, in the demo when a row index fails the range check,
  the column index is left on the stack. In real operations using a
  throw or abort this would be a don't care.  
[THEN]

\ C-STYLE ARRAY INDEXING

\ FACTORED ARRAY INDEX RANGE CHECK
: _? ( I A -- I A)

  0= IF ." (!) RANGE ERROR " DROP . REFILL DROP THEN ;

\ DISPLAY TEST RESULT
: =? ( N1 N2 --) = IF ."  YES" ELSE ."  NO" THEN ;

\ CREATE FIXED SIZED SLANTED ARRAY
ALIGN
3 , HERE 00 , 01 , 02 ,            \ COLUMN SIZE AND 3 ELEMENTS
4 , HERE 10 , 11 , 12 , 13 ,       \ COLUMN SIZE AND 4 ELEMENTS
5 , HERE 20 , 21 , 22 , 23 , 24 ,  \ COLUMN SIZE AND 5 ELEMENTS
3 , HERE 3 ROLL , ROT , SWAP ,     \ ROW SIZE AND ROW VECTORS
CONSTANT CC                        \ ARRAY ADDRESS

\ EXAMPLE CHECKING
2  0 CC    []    [] 02 =?    \ PASSED,
2  0 CC _? [] _? [] 02 =?    \ PASSED,
3  1 CC _? [] _? [] 13 =?    \ PASSED,
4  2 CC _? [] _? [] 24 =?    \ PASSED,
2 -1 CC _? [] _? []
. \ ROW CHECK FAILED SO COLUMN INDEX WAS LEFT OVER
3  0 CC _? [] _? []
4  1 CC _? [] _? []
5  2 CC _? [] _? []

--
Tom Zegub
WasteLand   http://www.*-*-*.com/ ~tzegub



Tue, 27 Nov 2001 03:00:00 GMT  
 factored range checking
The actual URL for Michael Gassenko's informative paper appears to be:

        http://www.forth.org.ru/~mlg/CStyleIn/CStyleIndexing.html

- Bob Cunningham

Quote:

> 0 [IF] DEMO - FACTORED INDEX RANGE CHECKING
>     Michael Gassenenko in his paper _C-Style Indexing in ANS Forth_
>   (www.forth.org.ru/mlg/cstyle.htm) presents a nice set of simple
>   array words. ...



Wed, 28 Nov 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. To factor or not to factor , that is a question

2. EIP and range checking

3. Checking 2 Ranges

4. VO: want to change range check for FieldSpec in DataWindow

5. Range Check Query

6. Range-checking in subunits

7. range checking

8. tcl8.1 Tcl_GetInt range checking broken on 64bit OS

9. Check number within range

10. Date range checking examples wanted

11. CW4 - Ranges question - changing range values while running

12. Range limits type : Range of values

 

 
Powered by phpBB® Forum Software