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


Groups > comp.lang.forth > #37694

Deep counting

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Deep counting
Date 2015-03-27 19:35 +0000
Organization A noiseless patient Spider
Message-ID <mf4beb$avu$1@dont-email.me> (permalink)

Show all headers | View raw


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 comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web