(;: 'a b c') i. <'a' NB. not found
3
   (;: 'aa bb cc') i. <'aa' NB. found
0

First lookup fails because:
$ &.> (;: 'a b c')
+-+-+-+
|1|1|1|
+-+-+-+
   $ &.> <'a'
++
|   |
++

Is there an easy way to deal with this?

So far I am trying to write something to bring $ 'a' up to 1 rather
than empty when it is empty.

   b =. (0&=...@$@$)
   b 'a'
1
   b 'aa'
0

So I try to use ^: to apply ,: conditional on b because I need to
apply ,: once if it 1 and 0 times if it is zero.

$ ,: 'a' NB. if I apply ,: once to 'a' then I get the shape I want,
but I do not want to apply it to lengths of more than one character
1

  (;: 'a b c') i. <  ,: 'a' NB. this is what I want
0

Anyway, I cannot figure out how to make it work:

 $  ,: 'a'
1
   b 'a'
1
   $ (,: ^: b) 'a' NB. why has this not applied ,: once to 'a' given
that b 'a' is 1?
1 1


   $ (,: ^: b) 'aa' NB. why has this applied ,: to 'aa' given that b 'aa' is 0?
1 2

b 'aa'
0

Basically, I have a string of tokens (such as 'a b c aa bb cc') which
are space separated and may contain either a single or more than a
single character each.

I have a value to look up in the list of tokens, but because of:
   (;: 'a b c') i. <'a' NB. not found
3
I am struggling :-)). Does anybody have any hints?

Thanks,
Matthew.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to