A concatenative, stack-based programming language with roots in Forth.
Latest Release: 11.2 (January 2012)
( chess.rx )
{{
: $, ( $- ) withLength [ @+ , ] times drop ;
create blank
"rnbqkbnrpppppppp" $,
"................" $,
"................" $,
"PPPPPPPPRNBQKBNR" $, 0 ,
create board
64 allot
: --- ( - )
" +-----------------+\n" puts ;
: ### ( - )
" 0 1 2 3 4 5 6 7 \n" puts ;
: row ( a-a )
"%d | " puts 8 [ @+ putc space ] times
"|\n" puts ;
: r,c ( ""-nn )
', accept tib toNumber getToken
toNumber swap ;
: get ( ""-a ) r,c 8 * board 2+ ;
---reveal---
: display ( - )
cr ### --- board 8 [ row ] iter drop
--- ### cr ;
: new ( - )
blank board 64 copy display ;
: move ( ""- )
get dup @ [ '. swap ! ] dip get ! display ;
}}
( grep.rx )
( Usage: "filename" "substring" grep )
( display all lines containing )
( "substring" in "filename" )
{{
2 elements token content
: clean ( $- )
withLength
[ dup @ 10 13 within
[ 999 swap &! sip ] ifTrue 1+ ] times
drop ;
: getLine ( $-$$ )
999 ^strings'splitAtChar ^strings'chop ;
: process ( $- )
dup @token ^strings'search
[ puts cr ] &drop if ;
: loadSourceData ( $- )
here swap ^files'slurp here !content heap +!
32 , 0 , @content clean ;
: eachLine ( $- )
[ getLine process dup 1 <> ] while drop ;
---reveal---
: grep ( $$- )
cr keepString !token
heap [ loadSourceData @content eachLine ]
preserve ;
}}