On Tue, Oct 7, 2008 at 5:19 AM, Alex Rufon <[EMAIL PROTECTED]> wrote:
> Playing with this we get:
> NB. converting from string to numbers
>   searchLOOKUP ;: 'The quick brown fox jumped'
> 12 13 14 15 16
>   searchLOOKUP 'fox'
> 15
>   searchLOOKUP 'Fox'
> 17
> NB. converting from numbers to string
>   4 14 15 { LOOKUP
> +-+-----+---+
> |3|brown|fox|
> +-+-----+---+
>
> Any ideas how to do this better?

You could improve the space efficiency of this system, by
using a flat string representation of your lookup variable.

3 :0 'safely initialize LOOK_up_'
  if. 0 ~: 4!:0<'LOOK_up_' do.
    LOOK_up_=:''
  end.
)

searchLOOKUP=: 3 :0
  assert (2 131072 e.~3!:0)S:0 y NB. is character type
  assert ([EMAIL PROTECTED])S:0 y            NB. rank
  assert 1 >: L.y                NB. depth
  values=. boxopen y
  r=.values (E.i.1:)S:0 LOOK_up_
  if. (#LOOK_up_) e. r=.values (E.i.1:)S:0 LOOK_up_ do.
    b=. r = #LOOK_up_
    newvals=. }:+/\(#LOOK_up_),#@>b#values
    LOOK_up_=:LOOK_up_,;b#values
    r=. newvals (I.b)} r
  end.
  r,.#@>values
)

LOOKUP=: ".bind'LOOK_up_' (<@:{~ (+i.)/)"1 ]

   searchLOOKUP ;:'the quick brown fox'
 0 3
 3 5
 8 5
13 3
   LOOKUP searchLOOKUP ;:'the quick brown fox'
+---+-----+-----+---+
|the|quick|brown|fox|
+---+-----+-----+---+
   LOOKUP searchLOOKUP ;:'the quick brown fox jumps'
+---+-----+-----+---+-----+
|the|quick|brown|fox|jumps|
+---+-----+-----+---+-----+

I do not know if this would be an improvement for your
situation.

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to