Differences From Artifact [956ace668efe5c42]:
File user/marc/box.rx part of check-in [600c7f8b01] - Update box.rx -- refactoring. by marc on 2011-01-18 22:43:19. [annotate] [view]
To Artifact [0e74434e73985e67]:
File user/marc/box.rx part of check-in [5a766a8dcb] - minor cleanups/use of combinators (box.rx) by crc on 2011-01-19 14:44:33. [annotate] [view]
@@ -17,17 +17,16 @@
chain: box'
( --[ Box geometry ]------------------------------------------ )
-variable boxWidth 16 boxWidth !
-variable boxMargin 4 boxMargin !
-variable box/line 4 box/line !
+16 variable: boxWidth
+ 4 variable: boxMargin
+ 4 variable: box/line
{{
( --[ Core ]------------------------------------------------ )
- : (putcs) ( cn-cn ) repeat dup 0 = if; over putc 1- again ;
- : putcs ( cn- ) (putcs) 2drop ;
+ : putcs ( cn- ) [ dup putc ] times drop ;
: padCount ( n-n ) @boxWidth @boxMargin - swap - ;
: .pad ( n-n ) padCount 32 swap putcs ;
: .pads ( $- ) withLength swap puts .pad ;
@@ -37,9 +36,9 @@
: .empty ( - ) '| putc -2 .pad '| putc ;
: xt->name ( a-$ ) xt->d dup [ d->name ] [ drop "" ] if ;
- 0 variable: escCell
+ variable escCell
: lookup ( a-$ )
@escCell
[ toString escCell off ]
[ instr? [ [ escCell on ] ifTrue ] [ xt->name ] if ] if ;
@@ -50,9 +49,9 @@
: .rule ( - ) '| putc '- .fill '| putc ;
( --[ Diagram for N contiguous cells ]---------------------- )
- 6 constant boxRows here boxRows allot constant boxtbl
+ 6 constant boxRows create boxtbl boxRows allot
boxtbl variable: currentRow
: boxRow, @currentRow ! currentRow ++ ;
@@ -64,26 +63,26 @@
[ ( a- ) .edge drop ; ] boxRow,
: (.row) ( aqn-aqn )
repeat dup 0 = if;
- push over 1+ push tuck do pop swap pop 1- again ;
+ [ over 1+ [ tuck do ] dip swap ] dip 1- again ;
: .row ( aqn- ) cr (.row) 2drop drop ;
: (.cells) ( an- )
- 0 repeat dup boxRows = if; dup 1+ push ( ann ) boxtbl + @ ( anq )
- push 2dup pop swap .row ( an ) pop again ;
+ 0 repeat dup boxRows = if; dup 1+
+ [ ( ann ) boxtbl + @ ( anq ) &2dup dip swap .row ( an ) ] dip again ;
( --[ Utility words for finding the RET opcode ]------------ )
- : ret? ( a-f ) dup @ 9 = swap 1+ @ 9 = and ;
+ : ret? ( a-f ) @+ swap @ [ 9 = ] bi@ and ;
: findRet ( a-na ) 1 swap repeat dup ret? if;
swap 1+ swap 1+ again ;
---reveal---
: .cells ( an- )
dup @box/line >
- [ @box/line - push @box/line (.cells) drop + pop .cells ]
+ [ @box/line - [ @box/line (.cells) drop + ] dip .cells ]
[ (.cells) 2drop drop ] if ;
: .cell ( a- ) 1 .cells ;
: .thread ( a- ) dup findRet drop .cells ;
@@ -92,6 +91,7 @@
}}
;chain
global with box'
+
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )