Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #37694 > unrolled thread

Deep counting

Started by"WJ" <w_a_x_man@yahoo.com>
First post2015-03-27 19:35 +0000
Last post2015-03-27 19:35 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.forth


Contents

  Deep counting "WJ" <w_a_x_man@yahoo.com> - 2015-03-27 19:35 +0000

#37694 — Deep counting

From"WJ" <w_a_x_man@yahoo.com>
Date2015-03-27 19:35 +0000
SubjectDeep 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

[toc] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web