Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #37694 > unrolled thread
| Started by | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| First post | 2015-03-27 19:35 +0000 |
| Last post | 2015-03-27 19:35 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.forth
Deep counting "WJ" <w_a_x_man@yahoo.com> - 2015-03-27 19:35 +0000
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2015-03-27 19:35 +0000 |
| Subject | Deep counting |
| Message-ID | <mf4beb$avu$1@dont-email.me> |
Count the number of times an item is found in nested
lists.
Oforth:
func: tally( item, list )
{| x |
0 list
forEach: x [
x isA( List )
ifTrue: [ tally( item, x ) ]
else: [ x item == abs ]
+ ] }
[0, [2, 3, [4, 2, 8], 2], 7] tally( 2 ) println
===>
3
[0, [2, 3, [4, 2, 8], 2], 7, 2] tally( 2 ) println
===>
4
Back to top | Article view | comp.lang.forth
csiph-web