Below I add my solution, verbs r2 and thedata , to the puzzle about retrieval
verb r's inability to notice changes in the database d. I like r2 plus thedata
because they identify and remove the problem in a simple way. Verb r2 is
tacit.
Confirming Dan's analysis, verb thedata is explicit. /Kip Murray
NB. database puzzle for forum
]d =: 7 3 $ 'dogbowwowpuprufcurgrr'
dog
bow
wow
pup
ruf
cur
grr
r =: (d"_ {~ ] |~ [: # d"_)"0
r1 =: 3 : 'd {~ y |~ #d' NB. Dan Bron
r2 =: thedata {~ ] |~ [: # thedata NB. Kip Murray
thedata =: 3 : 'd' NB. Kip Murray
NB. Hint. See what happens when you do
]d =: d , 'kty',:'mew'
dog
bow
wow
pup
ruf
cur
grr
kty
mew
d i. 'kty' NB. locate 'kty' in d
7
r NB. verb r has old d "hardcoded"
((7 3$'dogbowwowpuprufcurgrr')"_ {~ ] |~ [: # (7 3$'dogbowwowpuprufcurgrr')"_)"0
r 7 + i. 5 NB. r retrieves from old d (circles to top of old d)
dog
bow
wow
pup
ruf
r1 7 + i. 5 NB. r1 retrieves from new d
kty
mew
dog
bow
wow
r2 7 + i. 5 NB. r2 retrieves from new d
kty
mew
dog
bow
wow
Kip Murray wrote:
> 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.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm