update more examples to use new word names

FossilOrigin-Name: 708314f58b4253b273c217a11265725bad4c8d7d7c53c503510440dade50be4d
This commit is contained in:
crc 2020-07-06 02:49:49 +00:00
parent 71029ab555
commit 2e95ec501a
16 changed files with 42 additions and 42 deletions

View file

@ -20,7 +20,7 @@ Here is an example:
(comparison &gt? &lt?-or-gt? set-hook )
(begin_with #-1 !Index n:MIN !Value dup a:length ) ;
:min-or-max (a-nn) [ dup I@ dup @Value lt?-or-gt?
[ !Value I !Index ] [ drop ] choose ] times<with-index>
[ !Value I !Index ] [ drop ] choose ] indexed-times
(a-nn drop @Index @Value ) ;
---reveal---
:a:min (a-iv) pre.min min-or-max ;

View file

@ -37,7 +37,7 @@ Works imperfectly, but useful.
@Word d:link search dup n:zero?
[ drop SOURCE/RETRO ] [ d:name ] choose !FileName ;
:count-lines (-) #1 !Line
(open @FileName file:open<for-reading> !FileID !Size )
(open @FileName file:open-for-reading !FileID !Size )
[ @FileID file:read-line word-name s:contains-string?
dup [ &Line v:inc ] -if not (-eof? @FileID file:tell @Size lt? ) and ]
while (close @FileID file:close ) ;

View file

@ -97,7 +97,7 @@ So with two modes I only need one variable to track which mode is
active, and a single word to switch back and forth between them.
~~~
$C 'Mode var<n>
$C 'Mode var-n
:toggle-mode (-) @Mode $C eq? [ $I ] [ $C ] choose !Mode ;
~~~
@ -188,12 +188,12 @@ string. It then tries to find this in the dictionary.
[ 'roo:i:_ ] choose [ #6 + store ] sip d:lookup ;
~~~
With that, I can implement another helper: `call<dt>`, which will take
With that, I can implement another helper: `call-dt`, which will take
the dictionary token returned by `handler-for` and call the xt for the
word.
~~~
:call<dt> (d-) d:xt fetch call ;
:call-dt (d-) d:xt fetch call ;
~~~
The final piece is the top level key handler. This has the following
@ -208,9 +208,9 @@ jobs:
~~~
:handle-key (c-)
dup handler-for
@Mode $I -eq? [ nip 0; call<dt> ]
@Mode $I -eq? [ nip 0; call-dt ]
[ dup n:zero? [ drop insert-character ]
[ nip call<dt> ] choose ] choose ;
[ nip call-dt ] choose ] choose ;
~~~
Having finished this, it's trivial to define the majority of the basic

View file

@ -5,7 +5,7 @@ I begin by creating a variable for the current base and words to
set this to specific values quickly.
~~~
#10 'Base var<n>
#10 'Base var-n
:decimal #10 !Base ;
:binary #2 !Base ;
@ -42,7 +42,7 @@ here is:
:convert (c-) &DIGITS swap s:index-of @Number @Base * + !Number ;
:check-sign (s-s) dup fetch $- eq? [ #-1 !Mod n:inc ] [ #1 !Mod ] choose ;
---reveal---
:s:to-number<with-base> (s-n)
:s:to-number-with-base (s-n)
#0 !Number check-sign [ convert ] s:for-each @Number @Mod * ;
}}
~~~
@ -64,13 +64,13 @@ Going the other way, back to a string, follows a similar process.
:n->digit (n-c) &DIGITS + fetch ;
:convert (n-) [ @Base /mod swap n->digit buffer:add dup n:zero? ] until drop ;
---reveal---
:n:to-string<with-base> (n-s)
:n:to-string-with-base (n-s)
[ &String buffer:set dup n:abs convert check-sign ] buffer:preserve
&String s:reverse ;
}}
~~~
The `n:to-string<with-base>` returns a representation of binary numbers, but
The `n:to-string-with-base` returns a representation of binary numbers, but
not the actual bitwise representation. The next word takes care of this.
~~~

View file

@ -52,7 +52,7 @@ with tradition as well as the minimal requirements of ANS.
:BEGIN |repeat ; immediate
:AGAIN |again ; immediate
:FOR |[ ; immediate
:NEXT |] |times<with-index> ; immediate
:NEXT |] |indexed-times ; immediate
:DO |[ |[ |[ ; immediate
:LOOP |] |dip |] |dip |n:inc |dup-pair |gt? |] |while |drop-pair ; immediate
:+LOOP |] |dip |] |dip |swap |push |+ |pop |swap |dup-pair |gt? |] |while |drop-pair ; immediate

View file

@ -100,13 +100,13 @@ Space is also reserved for the *next generation*.
dup-pair get #1 eq? &alive &dead choose ;
:set (nrc-) &Next + [ #20 * ] dip + store ;
:cols (r-)
#20 [ I over swap new-state rot rot set ] times<with-index> drop ;
#20 [ I over swap new-state rot rot set ] indexed-times drop ;
:output (n-) n:-zero? [ $o ] [ $. ] choose c:put sp ;
---reveal---
:display (-)
nl &World #20 [ #20 [ fetch-next output ] times nl ] times drop ;
:gen (-)
#20 [ I cols ] times<with-index> &Next &World #20 #20 * copy ;
#20 [ I cols ] indexed-times &Next &World #20 #20 * copy ;
}}
{{

View file

@ -17,6 +17,6 @@ description of each.
'unknown:_ s:put n:put nl ;
'Detecting_devices... s:put nl
io:enumerate [ $# c:put I dup n:put io:query nip tab id ] times<with-index>
io:enumerate [ $# c:put I dup n:put io:query nip tab id ] indexed-times
'Complete. s:put nl
~~~

View file

@ -49,7 +49,7 @@ a few variables and constants.
Get the name of the file to edit.
~~~
#0 sys:argv s:keep 'SourceFile var<n>
#0 sys:argv s:keep 'SourceFile var-n
~~~

View file

@ -16,8 +16,8 @@ set of aliases or extensions to make things more readable. E.g.,
Rather than:
#1 ll:node<n> #2 ll:node<n> ll:append #3 ll:node<n>
ll:append #4 ll:node<n> ll:append
#1 ll:node-n #2 ll:node-n ll:append #3 ll:node-n
ll:append #4 ll:node-n ll:append
It's easy to write wrappers that allow for things like:
@ -34,14 +34,14 @@ So:
ll:head (a-a) return the address of the head field for a node
ll:next (a-a) return the address of the next field for a node
ll:node<n> (n-a) create a new node with a head of n and a next of 0
ll:node-n (n-a) create a new node with a head of n and a next of 0
ll:node (-a) create a new node with both fields set to 0
~~~
:ll:head ;
:ll:next n:inc ;
:ll:node<n> here swap , #0 , ;
:ll:node-n here swap , #0 , ;
:ll:node here #0 , #0 , ;
~~~
@ -60,8 +60,8 @@ to the end of the list.
I have a `for-each` combinator to handle performing an action on
each node in a list. As an example:
:< ll:node<n> ;
:> ll:node<n> ll:append ;
:< ll:node-n ;
:> ll:node-n ll:append ;
#1 < #2 > #3 > #5 > #1 > #2 > #3 >
[ ll:head fetch n:put sp ] ll:for-each
@ -94,7 +94,7 @@ The docstring for this is:
Tests
```
:< ll:node<n> ;
:> ll:node<n> ll:append ;
:< ll:node-n ;
:> ll:node-n ll:append ;
#1 < #2 > #3 > #5 > #1 > #2 > #3 > [ ll:head fetch n:put sp ] ll:for-each
```

View file

@ -37,7 +37,7 @@ And if you need multiple variables to be localized:
~~~
:make-local (a-)
here [ compile:lit
d:last<xt> compile:lit
d:last.xt compile:lit
&v:preserve compile:call
compile:ret ] dip d:last d:xt store ;

View file

@ -11,11 +11,11 @@ The initial maximum number of iterations is set to 128.
'y var
'iter var
#128 'max-iter var<n>
#128 'max-iter var-n
#1 'zoom var<n>
#0 'posx var<n>
#0 'posy var<n>
#1 'zoom var-n
#0 'posx var-n
#0 'posy var-n
~~~
We are using fixed-point numbers with a scaling factor of 10'000.
@ -123,9 +123,9 @@ height.
J #800 * #10000 - @zoom / @posy +
mb:value
ascii-equiv c:put
] times<with-index>
] indexed-times
nl
] times<with-index> ;
] indexed-times ;
~~~
Before we start, the terminal is set to character-buffered. This makes

View file

@ -19,7 +19,7 @@ First, words defined elsewhere.
[ d:lookup ] dip d:another-name ; 'alias d:aka
}}
'var<n> 'var! (n-) alias
'var-n 'var! (n-) alias
'lt? 'n:<? alias
'lteq? 'n:=<? alias
:v:put (a-) fetch n:put ;

View file

@ -5,23 +5,23 @@ First is a word to return values from a lower to upper limit, incrementing
upwards. The returned values are inclusive of the limits.
~~~
:range<inc> (lh-a)
over - n:inc [ I over + swap ] times<with-index> drop ;
:range-inc (lh-a)
over - n:inc [ I over + swap ] indexed-times drop ;
~~~
Next is a word to return values from an upper to lower limit, decrementing
upwards. The returned values are inclusive of the limits.
~~~
:range<dec> (hl-a)
over &- dip swap n:inc [ I over swap - swap ] times<with-index> drop ;
:range-dec (hl-a)
over &- dip swap n:inc [ I over swap - swap ] indexed-times drop ;
~~~
The last word takes the limits and calls the appropriate word.
~~~
:range (nn-a)
dup-pair gt? [ range<dec> ] [ range<inc> ] choose ;
dup-pair gt? [ range-dec ] [ range-inc ] choose ;
~~~
As a simple test case:

View file

@ -73,7 +73,7 @@ constraints)
[ !R ] [ q:free ] [ q:length ] tri
'\nin_que:_%n,_free:_%n s:format s:put
@R q:length n:strictly-positive?
[ @R q:size [ display indicators ] times<with-index> ]
[ @R q:size [ display indicators ] indexed-times ]
[ 'queue_is_empty s:put nl ] choose ;
}}
~~~

View file

@ -54,8 +54,8 @@ progresses. I will fill in the value for `interpret` later.
~~~
#1025 &Image + 'TIB const
#367 't:interpret var<n>
#339 't:notfound var<n>
#367 't:interpret var-n
#339 't:notfound var-n
~~~
I next define helpers to move values to/from the host data

View file

@ -29,7 +29,7 @@ XOR/rotate/shift/rotate PNRG (See http://xoshiro.di.unimi.it/)
\popopopo \popopopo ;
:jump? (nm-) [ JUMP + fetch ] dip #1 swap n:negate shift and ;
:inner (n-n)
#32 [ dup I jump? [ [ xor-er ] dip ] if next ] times<with-index> ;
#32 [ dup I jump? [ [ xor-er ] dip ] if next ] indexed-times ;
---reveal---
:random:xoroshiro128** (-n)
@ -37,7 +37,7 @@ XOR/rotate/shift/rotate PNRG (See http://xoshiro.di.unimi.it/)
:random:xoroshiro128**:jump (-)
#0 &s3 #0 &s2 #0 &s1 #0 &s0
#4 [ I inner drop ] times<with-index>
#4 [ I inner drop ] indexed-times
\stststst ;
:random:xoroshiro128**:set-seed (n-)