add example/CloseParen.forth
FossilOrigin-Name: 2e440f95f4058f94bd270dd2f510b87bb73ab813e7bd08e8bd1c453e8b14b3df
This commit is contained in:
parent
dc7feb982c
commit
eb9383a639
2 changed files with 36 additions and 0 deletions
|
@ -152,6 +152,7 @@ June 2019.
|
|||
- add Block-Editor.forth
|
||||
- add Buffer.forth
|
||||
- add CaptureOutput.forth
|
||||
- add CloseParen.forth
|
||||
- add DisplayNames.forth
|
||||
- add EDA.forth
|
||||
- add EvaluateString.forth
|
||||
|
|
35
example/CloseParen.forth
Normal file
35
example/CloseParen.forth
Normal file
|
@ -0,0 +1,35 @@
|
|||
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
|
||||
```
|
||||
|
Loading…
Reference in a new issue