Eh.. it's possible, but I do not think you should want a syntax error
here. I think you should want a domain error or an index error.

Syntax error is for sentences like 0 1+), domain error is for things
like 0 1+'ab' and index error is for things like 2{'ab'

That said, I would also take issue with your naming. For example, what
your 'var' is doing is checking whether an argument is a numeric
integer (internal type of integer or boolean), so I would replace that
definition with:

isInt=: e.&1 4@(3!:0)

But then... I also look at how this is being used and... it's way more
complicated than I think it needs to be, based on your description of
what you are doing. And, so is your right argument for 'find'. So
before I could make adequate recommendations there, I think I would
need to know why you're doing things this way.

In particular, you're using recursion, and using an error handler to
terminate your recursion. This will interfere with any attempt to
yield errors. But there seems to be no requirement for recursion in
your message.

I also don't understand the leading 0 in your data structure, nor do I
understand why you're using boxing in your right argument but not in
your result.

For example, consider
   1 2 (1&{::@] {~ 0&{::@] i. [) (2 1;4 9)
9 4

This does what you seem to be asking for, except I've left out some
pieces and some boxing. It could be rephrased to include some or all
of that, but I'm not sure which parts of the added complexity reflect
your requirements, because I don't understand your requirements. It
doesn't directly support the empty argument of your second example,
but if that's doing what I think it's doing, it would be better
handled by omitting the associated keys from the data structure.

Anyways... hopefully some of this is relevant. And, if I'm too far off
base, please describe the issues...

Thanks,


--
Raul

On Wed, Feb 19, 2020 at 4:41 PM Raoul Schorer <raoul.scho...@gmail.com> wrote:
>
> Hi,
>
> I have a 'find' dyadic verb that takes a (array of) integer(s), walks
> the associative array recursively and yields the current element when
> not found in the associative array, as below:
>
> var =: (4&=+.1&=)@(3!:0)
>
> find =:([`((]$:~]{::~2;<@[i.~1&{::@]) :: [)@.(var@[))"(0 _)
>
> Examples:
>
> (1 2) find (0;(2;1);<(5.22;3.5))
>
> (2 1) find (0;(2;1);<('';3.5))
>
> Now, the 1st example works as expected, but when unifying with the empty
> list as in the 2nd example I get zeroes that (apparently??) are fill
> atoms. I'd like my result to respect J syntax (for syntactic
> unification) and therefore where the second example yields '0 3.5' I
> would like to get a syntax error.
>
> Is this possible? One way I thought of would be to build the result as a
> string and execute it, but that would be dog-slow on larger data,
> wouldn't it?
>
> Thanks for your consideration,
>
> Raoul
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to