Dan, thank you for your discussion, which is exactly what I needed: a framework
for spotting errors like mine without having to discover them the hard way.
Below I show the error I was referring to and your correction which avoids the
error. I apologize for referring to it as an error in verb r. It was an error
I made in defining r. In the following, note that I define your explicit verb
r
(named r1 here) as I did my r , BEFORE amending the database d .
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'S EXPLICIT r
NB. Hint. See what happens when you do
]d =: d , 'kty',:'mew'
dog
bow
wow
pup
ruf
cur
grr
kty
mew
r NB. IMMUTABLE, WILL RETRIEVE FROM THE ORIGINAL d
((7 3$'dogbowwowpuprufcurgrr')"_ {~ ] |~ [: # (7 3$'dogbowwowpuprufcurgrr')"_)"0
d i. 'kty'
7
r 7 + i. 5 NB. Not what I want!
dog
bow
wow
pup
ruf
r1 7 + i. 5 NB. DAN'S r1 RETRIEVES FROM THE NEW d
kty
mew
dog
bow
wow
Again, thank you, Dan, for teaching me how to think about this.
Kip
Dan Bron wrote:
> 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.
>
> I'm not sure what your question is, or what the error you refer to is.
>
> However, I do know that these two concepts:
>
>> r =: (d"_ {~ ] |~ [: # d"_)"0
>> d =: d , 'kty',:'mew'
>
> are incompatible. Tacit code is functional code. Given the same inputs,
> it produces the same output. The only thing that can cause a tacit verb
> to produce different outputs is different inputs. The only "mutable"
> thing about a tacit verb is its arguments, which it does not mention; so a
> tacit verb is immutable [1].
>
> But you're trying to make a mutable tacit verb, which is a contradiction.
> You're treating d like an argument, without making it an argument (or,
> alternatively, you're trying to make a tacit verb mention its argument).
> So you're going to have problems. When you defined r the value of d
> was "compiled in".
>
> You can't have it both ways. If you want to refer to mutable global nouns,
> you're going to have to use explicit code. Now, there are tricky ways to
> get the behavior you want, such as replacing d"_ with ". bind 'd' ,
> but the "trickee" would be you.
>
> To use the example above: ". is a J interpreter, in ". bind 'd' you're
> giving it d to interpret, which is a noun phrase, which isn't tacit;
> hence r is not tacit. Put another way, you would just be fooling
> yourself. There are other tricky ways and they'd all fall victim to the
> same sort of analysis [2].
>
> In the end, to refer to mutual global data is to express an explicit verb.
> If you want to express an explicit verb, why not do it the easy way?
> r =: 3 : 'd {~ y |~ #d'
>
> Now, if you're particularly charmed by the tacit expression and don't want
> to rephrase it explicitly, you could always take a hybrid approach:
>
> r =: 3 : 'd' : ([ {~ #...@[ | ])
>
> as long as you're ok with the fact that while ([ {~ #...@[ | ]) is tacit, r
> isn't.
>
> -Dan
>
>
> [1] Well, I suppose if a tacit verb f depended on another tacit verb g,
> you could redefine g and f will have "mutated". But to that I would say
> that you haven't mutated f, you've redefined it. The new f is a different
> verb. Put another way, in the context of my message above, a tacit verb
> is a fully fixed, anonymous verb composed soley of primitives and
> anonymous nouns, which makes no use of n : .
>
> [2] The one exception would be memory-mapping d , but while this is
> "tacit", it is still not functional. It's basically a cheat, and it's a
> lot more work than it's worth.
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm