I mentioned (a=:0](a) because we seem to be talking about changing the
implementation.
Specifically, if we are going to be introducing optimizations which
damage the value of a in some fashion where the interpreter cannot
restore it, I think we should restrict those optimizations to cases
where the code has clearly indicated that damaging a in the error case
is acceptable.
I do not see any good reason for accepting this behavior:
a=: 3 1 4 1 5 9 2
a =: ('b' ,~ 3 ,~ ]) a
|domain error
| a=: ('b',~3,~])a
a
3 1 4 1 5 9 2 3
That is not how J has worked in the past, it does not correspond to
the dictionary description of how parsing works, it seems unnecessary,
and I believe it's only there because of an "optimization".
A problem is: if you optimize for incorrect behavior, you wind up with
something that does the wrong thing, real fast.
And, ok, in some contexts that kind of thing can be an important compromise.
In this case, however, it seems entirely unnecessary.
That said, if you think I have overlooked something important, please
educate me.
Thanks,
--
Raul
On Mon, Oct 3, 2016 at 8:59 PM, Henry Rich <[email protected]> wrote:
> The (a=:0)](a) trick, while clever, does not work in the implementation
> because (a =: 0) does not actually reduce the usecount of a until the
> sentence completes.
>
> Henry Rich
>
>
> On 10/3/2016 7:21 PM, Raul Miller wrote:
>>
>> This has been bothering me. After sleeping on it, I think I know how
>> to articulate my concerns:
>>
>> It seems unnecessary.
>>
>> First, the error handling in this case could restore the shape of a to
>> its original value and that seems like it should be simple.
>>
>> However, also, in hypothetical analogous cases where error recovery
>> would be difficult, there's another approach that could be used:
>> replace the reference to a with (a=:0)](a)
>>
>> This frees a's reference to the array, and makes it clear, also, that
>> it's good to destroy a when an error occurs.
>>
>> a =: b ([ ,~ 3 ,~ ]) (a=:0)](a)
>>
>> (Note also that the parenthesis around a are not optional here. There
>> are other expressions which achieve the same effect, but you can't use
>> just a bare a there and have it work right.)
>>
>> Thanks,
>>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm