This puzzle has two parts (a) what is the error in verb r, and (b) how do you
fix it? I have an answer for the fix, but there may be better ones.
Verb r retrieves data from the database d. However, there is no index error
for
an out of bounds index. Instead, r treats d as a circle, and keeps going
around
the circle as dictated by the index:
NB. database puzzle for forum
]d =: 7 3 $ 'dogbowwowpuprufcurgrr'
dog
bow
wow
pup
ruf
cur
grr
r =: (d"_ {~ ] |~ [: # d"_)"0
r 0 1 2
dog
bow
wow
d i. 'cur'
5
r 5 + i. 5
cur
grr
dog
bow
wow
NB. Hint. See what happens when you do
]d =: d , 'kty',:'mew'
dog
bow
wow
pup
ruf
cur
grr
kty
mew
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm