new example
FossilOrigin-Name: 45eb321e8e7d830d8d934818f1770f585d65c72ba1e83b5b15f9e6c3559929a9
This commit is contained in:
parent
be25e2939c
commit
a4bec63227
1 changed files with 27 additions and 0 deletions
27
example/words-four-column.retro
Normal file
27
example/words-four-column.retro
Normal file
|
@ -0,0 +1,27 @@
|
|||
This is a four column version of `d:words`. It's pretty straightforward.
|
||||
|
||||
The code first scans through the dictionary to find the longest name. Shorter
|
||||
names will be padded to make sure all columns line up. It then displays each
|
||||
name, updating a column counter and adding newlines when needed.
|
||||
|
||||
~~~
|
||||
{{
|
||||
#3 'Columns var<n>
|
||||
'PadTo var
|
||||
:determine-padding
|
||||
#0 [ d:name s:length n:max ] d:for-each !PadTo ;
|
||||
:print-name
|
||||
d:name [ s:put ] [ s:length @PadTo swap - &sp times ] bi sp sp ;
|
||||
:wrap? @Columns n:zero? dup [ #4 !Columns ] if &Columns v:dec ;
|
||||
---reveal---
|
||||
:d:words-4
|
||||
determine-padding [ print-name wrap? &nl if ] d:for-each ;
|
||||
}}
|
||||
~~~
|
||||
|
||||
Test it.
|
||||
|
||||
```
|
||||
d:words-4
|
||||
```
|
||||
|
Loading…
Reference in a new issue