what's the motivation for J to introduce fork
Asked Answered
V

2

6

For the evolution from APL to J, What's the motivation to introduce fork? I guess it is nice to have (+/ % #) for calculating the average, but it also makes it harder to read longer verb train. Facing this tradeoff, is there any compelling reason for the APL inventor to choose this style in J?

Vanguard answered 23/1, 2014 at 14:26 Comment(1)
Your own answer summarizes the topic quite well. But I'd like to add why IMHO most people find (+/ % #) harder to read than {(+/⍵)÷≢⍵}. 1. The braces {} clearly identify that a new function is being defined; that's not at all clear in J's tacit style and it makes larger expressions harder to read (=parse by eye) 2. The syntax for combining existing functions is the same whether you're working at functional depth 0 (aka. regular programming) or higher (aka. functional programming): (+/A)÷≢A vs. {(+/⍵)÷≢⍵} and so on. 3. APL symbols are more distinct, and that makes them easier to read.Aquileia
V
4

Thanks for Bob's answer. To make it stronger, now I learned that the necessity of fork as below.

  • The motivation of introducing fork is to implement tacit programming as a realization of Combinatory logic. you need sort of basis combinators for this ( like the s-k basis on wiki) , and hook/fork form a complete basis. Fork or its equivalent is really unavoidable for this purpose.

  • the concept of fork is natural if thinking of f + g, f * g. In math they usually mean f(x) + g(x) and f(x) * g(x).

  • This topic was explained nicely in Roger Hui's essay on verb trains.

Vanguard answered 24/1, 2014 at 14:9 Comment(1)
I think your second bullet is an important one. To me J's trains feels like a more high-level way to express something, a lot like sum = foldl (+) 0 (or sum =: +/ in J) vs. a manual loop adding to a counter. Conversely, when I see an expression of the form x + f(x) or x * f(x) I immediately think "hey, that's a hook", even outside of J.Kayseri
B
3

I suppose that fork has the motivation of combining existing functions to form a new function. Composition of functions in J is represented by @: or @ to create a new function from functions f and g, f@:g. Which means take the results of g and process them with f

Fork does the same but allows us to process the results of two different functions (right and left tine) using a third function (central tine). So (f h g) applies the results of f and g to the central tine h. The fork construct is interesting because it is a way of generating a new function by grouping functions without needing an additional symbol. As you pointed out it is extendable so that (a b c d e) is read as (a b (c d e)) where the result of the fork c d e is used as the right tine.

Boole answered 23/1, 2014 at 23:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.