Bug in gerund"0?

50 views
Skip to first unread message

Jan-Pieter Jacobs

unread,
May 29, 2025, 3:39:02 AM5/29/25
to fo...@jsoftware.com
Recently, I was trying to solve another AoC problem, and ran into an error caused by a cornercase that I expected to "just work" as usually in J.

It boiled down to the following: I was constructing a gerund with the rank conjunction to apply a specific verb on between each pair of elements from two arrays, based on the elements. This worked fine, but not when the arrays, and therefore the gerund, were empty.

   $(1$1) (1$+`*)"0] 1$2 NB. as expected
1
   $(0$0) (1$+`*)"0] 0$0 NB. also expected
0
   $(0$0) (0$+`*)"0] 0$0 NB. weird
0 0
   $(1$0) (0$+`*)"0] 1$2 NB. don't know...
1 0
   $(0$0) +"0] 0$0 NB. for reference, the non-gerund case.
0
   $(0$0) + 0$0
0
   
So the case where the gerund is empty seems to behave in a way that appears anomalous; especially in the case where applied between empty arrays.
Between non-empty arrays, the result also seems suspicious to me, but I don't know whether it's an issue or not.

In my case, I discovered because I was using the result to amend an array, and there I got a rank error.

This is on J9.6 and J9.7
   JVERSION
Engine: j9.6.3/j64arm/android
Build: commercial/2025-04-05T16:47:34/clang-14-0-7/SLEEF=1
Library: 9.6.14
J Android: 1.4.87/14/34
Platform: Android 64 (arm64-v8a)
Installer: unknown
InstallPath: /storage/emulated/0/Android/data/com.jsoftware.j.android/files

Engine: j9.7.0-beta4/j64arm/android
Build: commercial/2025-05-08T21:53:23/clang-14-0-7/SLEEF=1
Library: 9.6.14
J Android: 1.4.87/14/34
Platform: Android 64 (arm64-v8a)
Installer: unknown
InstallPath: /storage/emulated/0/Android/data/com.jsoftware.j.beta.android/files

Maybe it's not a bug, but just something I don't understand...

Best regards,

Jan-Pieter

Henry Rich

unread,
May 29, 2025, 8:22:03 AM5/29/25
to fo...@jsoftware.com
m"n does double duty: originally m was any noun, and was the value for each result-cell.  The gerund"n form was discovered later.

m is treated as a gerund if it is boxed, nonempty, and each box looks like a gerund, and also n is not _ .  This explains your results.

I think this definition is reasonable.  What would (x empty"n y) mean as a gerund?  I am used to executing a verb on no data, but what does it mean to execute no verb on data?  As a dyad?

Henry Rich
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.

Jan-Pieter Jacobs

unread,
Jun 3, 2025, 3:59:57 PM6/3/25
to fo...@jsoftware.com
Thanks for your clarification, Henry!

I guess that with that context, I see how the shape of 0 0 comes about when considering an empty list of boxes doesn't look like a gerund. Because of this it's probably impossible to distinguish an empty gerund from an empty list of boxes.

I guess there is nothing better to do, as gerunds have their own type and an empty list of boxes is identical to a gerund without any verbs.

Best regards,
Jan-Pieter


Henry Rich

unread,
Jun 3, 2025, 4:17:19 PM6/3/25
to fo...@jsoftware.com
I agree that there is nothing better to do, but the root problem is the fact that gerunds /don't/ have their own type.

   <,'+'

is ambiguous: a boxed string or a gerund.  The gerund concept is cute, because it allows J code to create verbs on the fly, but I wish the language had defined a separate type.  The result of u`v would be a gerund, and (`:1) would be an adverb that converted a noun to a gerund, viz

 gerund =: unboxed_AR `:1

The gerund would be a separate noun type, looking like a box for all purposes except use in @. # / etc.

The current gerund form is also inefficient: it has to be parsed afresh whenever it is used.  Perhaps a special type could avoid that as well.



I would say that an empty list of boxes /does/ look like an empty gerund - at least that's surely what an empty gerund would look like - but m"n chooses not to interpret the empty list as a gerund because: What could (x empty_gerund y) possibly produce as a result?

Henry Rich

Jan-Pieter Jacobs

unread,
Jun 15, 2025, 5:27:51 AM6/15/25
to fo...@jsoftware.com
Hi Henry,

I agree with you on all these points.
If a gerund were a separate noun type, it could also have a fill element, a verb to be used by modifiers taking gerunds when a gerund is empty, or overtaken ({.).

Initially, I thought that it could make sense to have, as a gerund-fill element, a verb that returns an appropriately (taking into account $x, $y and rank(s) it is applied to) dimensioned array of the fill element of y?
Although if so, there's no way to know what shape/type of result a user expects from a verb if present, so probably it's not a solution either.

Even when an empty gerund is applied on arguments having no items (leading 0 in shape) (as was my case), it wouldn't be straightforward to assume a certain shape (including leading 0's depending on the rank the gerund is applied on) for the result.

So I guess the current implementation is as good as it gets.

Thanks for pointing that out.

Best regards,

Jan-Pieter
Reply all
Reply to author
Forward
0 new messages