Re:Thinking in an Array Language
by gcanyon on Saturday January 13, 2024 @01:25PM
(#38982904)
This is based on K. Another array language is J http://jsoftware.com In J this would be:
That will return 10, the dot product P and Q.
[ Parent
| on HN ]
The original array lang is APL:
dot←+.×
but why give it a name when spelling it out is as short as the shortest reasonable name for it (and then you might need to put spaces around the name).For people who understand the language, there is little point to naming it. For illustrating to people unfamiliar with the language, it helps to break apart the "this is the thing I'm talking about" part from the "here's how you would use it" part.
In KlongPy, dot product is: dot::{+/x*y}
P::[2 3 4]
Q::[1 0 2]
dot(P;Q)
Re:Thinking in an Array Language
by __marvin_the__ on Saturday January 13, 2024 @10:06PM
(#38987036)
TIL of KlongPy (and Klong). Looking at the project page, I think it looks really cool.
Re:Thinking in an Array Language
by nils-m-holm on Sunday January 14, 2024 @05:17AM
(#38989142)
> dot(P;Q)
You can also write P dot Q.
I guess I still fail to see the advantage of this over Haskell:
dot = (sum.) . zipWith (\*)
p = [2, 3, 4]
q = [1, 0, 2]
p `dot` q
Like, the only difference to my eyes is using names for sum/zipWith, and not having the lifts/restructuring happen "magically"
Re:Thinking in an Array Language
by RodgerTheGreat on Saturday January 13, 2024 @11:08PM
(#38987354)
The APL/J/K/Klong versions are more general; they all work for a variety of ranks of input, whereas the Haskell version- which is the longest and most visually noisy- bakes in a single rank's mapping explicitly.
Well, for one, your Haskell version is obviously much longer.
Re:Thinking in an Array Language
by dr_kiszonka on Sunday January 14, 2024 @04:06AM
(#38988749)
Haha!