eb9383a639
FossilOrigin-Name: 2e440f95f4058f94bd270dd2f510b87bb73ab813e7bd08e8bd1c453e8b14b3df
35 lines
862 B
Forth
35 lines
862 B
Forth
I find `)` useful to punctuate code chunks.
|
|
|
|
~~~
|
|
:) ; immediate (code_chunk_punctuation_that_does_nothing
|
|
~~~
|
|
|
|
Here is an example:
|
|
|
|
:i@ (an-n) array:nth fetch ;
|
|
|
|
~~~
|
|
{{
|
|
:I@ (an-n) I array:nth fetch ;
|
|
'Index 'Value [ var ] bi@
|
|
:lt?-or-gt? hook ;
|
|
:pre.min (a-an)
|
|
(comparison <? <?-or-gt? set-hook )
|
|
(begin_with #-1 !Index n:MAX !Value dup array:length ) ;
|
|
:pre.max (a-an)
|
|
(comparison >? <?-or-gt? set-hook )
|
|
(begin_with #-1 !Index n:MIN !Value dup array:length ) ;
|
|
:min-or-max (a-nn) [ dup I@ dup @Value lt?-or-gt?
|
|
[ !Value I !Index ] [ drop ] choose ] times<with-index>
|
|
(a-nn drop @Index @Value ) ;
|
|
---reveal---
|
|
:array:min (a-iv) pre.min min-or-max ;
|
|
:array:max (a-iv) pre.max min-or-max ;
|
|
}}
|
|
~~~
|
|
|
|
```
|
|
{ #3 #2 #5 #7 #3 } array:min dump-stack nl reset
|
|
{ #3 #2 #5 #7 #3 } array:max dump-stack nl
|
|
```
|
|
|