There was some discussion a year or two ago about this C-like “compound
assignment.” I’d liked it in Dyalog APL but others weren’t keen on its
incorporation in J.
I too had used the indexed increment idiom in Dyalog for building frequency
tables.
There was correspondence very recently on using “key” to build frequencies in
J.
So:
(<:@#/.~ @: ,~&(lc,' '))'short test' NB. prepend domain members
0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 2 3 0 0 0 0 0 0 1
(lc,' ')([<:@#/.~@:,e.~#])'short test1224' NB. Not counting non-members
0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 2 3 0 0 0 0 0 0 1
Very simple if you’re just counting what’s there...
#/.~ 'short test1224'
2 1 1 1 3 1 1 1 2 1
Mike
Sent from my iPad
> On 3 Nov 2019, at 22:13, Jimmy Gauvin <[email protected]> wrote:
>
> Hi,
>
> some APLs have a combination of assignment with a function, for example :
>
> a←⍳5
> a+←1
> a
> 2 3 4 5 6
>
> This can be combined with index to good effect, for example counting
> character occurrences in a text vector :
> ,bkt←0/⍨1+≢lc
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> bkt[lc⍳'short test']+←1
> bkt,[.5]lc,' '
> 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 2 3 0 0 0 0 0 0 1
> a b c d e f g h i j k l m n o p q r s t u v w x y z
>
> Is there something equivalent in J ?
> All I have come up with is the classical construct using the table operator
> :
>
> lc,:1": +/'short test'=/lc
>
> abcdefghijklmnopqrstuvwxyz
>
> 00001001000000100123000000
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm