Now I have an adverb mc that creates "mutable constants" for tacit verbs:

    NB. database solution for forum

    mc =: 1 : '3 : (m;'':'';m)'  NB. 'pronoun' mc is "mutable constant"

    ]d =: 7 3 $ 'dogbowwowpuprufcurgrr'   NB. database
dog
bow
wow
pup
ruf
cur
grr

    r =:       d"_ {~ ] |~ [: # d"_       NB. circular retrieve

    r3 =: ('d' mc) {~ ] |~ [: # ('d' mc)  NB. likewise

    r (d i. 'cur') + i. 5    NB.  circular retrieve continues from top of d
cur
grr
dog
bow
wow

    r3 (d i. 'cur') + i. 5   NB. likewise
cur
grr
dog
bow
wow

    NB. See what happens when you amend d

    ]d =: d , 'kty',:'mew'
dog
bow
wow
pup
ruf
cur
grr
kty
mew

    r (d i. 'kty') + i. 5   NB. circular retrieve from old d, not what I want
dog
bow
wow
pup
ruf

    r3 (d i. 'kty') + i. 5  NB. circular retrieve from new d, yes!
kty
mew
dog
bow
wow


Kip Murray wrote:
> 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

Reply via email to