Hacker News new | ask | show | jobs
by shric 997 days ago
My recent exposure to array programming languages came via a podcast called The Array Cast[1]

Not affiliated, just recommending. The regular co-hosts appear to each be experienced with various array languages such as J, APL, etc. They don't get deeply technical, but it's a nice introduction, especially on explaining the appeal.

A recent episode had Rob Pike (UTF-8, Go, etc.) on to talk about his array based calculator, Ivy[2]

[1] https://www.arraycast.com/

[2] https://github.com/robpike/ivy

3 comments

Our upcoming episode is an interview with Kai Schmidt, the creator of Uiua. It will be published this weekend. It turns out that Kai is a fan of the ArrayCast and it was his introduction into array programming.
Ah, awesome, really looking forward to it!
Can array languages be used as general purpose languages in any practical way? Or are they really only strong as calculators?
They can be. I know J has libraries for databases, image, audio processing, etc. I've written an assembler in J and translated it to K. The array languages are pretty decent for prototyping machine learning stuff. Often you don't need any libraries at all.

Here's a 2-layer perceptron, first in Python+NumPy:

    import numpy as np
    X = np.array([[0,0,1], [0,1,1], [1,0,1], [1,1,1]])
    y = np.array([[0,1,1,0]]).T
    np.random.seed(1)
    w0 = 2*np.random.random((3,4)) - 1
    w1 = 2*np.random.random((4,1)) - 1
    for j in range(10000):
        l1 = 1/(1+np.exp(-(X @ w0)))
        l2 = 1/(1+np.exp(-(l1 @ w1)))
        l2_error = y - l2
        l2_delta = l2_error * l2 * (1 - l2)
        l1_error = l2_delta @ w1.T
        l1_delta = l1_error * l1 * (1 - l1)
        w0 += X.T @ l1_delta
        w1 += l1.T @ l2_delta
    print(np.round(l2,3))
    [[0.007]
     [0.991]
     [0.992]
     [0.01 ]]
And again in J:

    input =: 4 3 $ 0 0 1  0 1 1  1 0 1  1 1 1
    target =: 4 1 $ 0 1 1 0
    dot =: +/ .*
    sig =: {{ %>:^-y }}
    train =: {{
        'ignore_me w0 w1' =. y
        l1 =. sig input dot w0
        l2 =. sig l1 dot w1
        l2_error =. target - l2
        l2_delta =. l2_error * l2 * 1 - l2
        l1_error =. l2_delta dot |: w1
        l1_delta =. l1_error * l1 * 1 - l1
        w0 =. w0 + (|:input) dot l1_delta
        w1 =. w1 + (|:l1) dot l2_delta
        l2;w0;w1 }}
    5j3":0{::train^:10000 {{<:+:?.y$0}} each 1 ; 3 4 ; 4 1
    0.009
    0.990
    0.990
    0.011
Here's that assembler (for the Nand2Tetris assembly language) in K. It's intentionally golfed.

    L:({x^"\r "}'*'"/"\'0:0)^,""
    T:(("R",'$!16)!!16),(($`SCREEN`KBD`SP`LCL`ARG`THIS`THAT)!16384,24576,!5),((-1_1_)'L@&i)!{x-!#x}@&i:"("=*'L
    T,:n!16+!#n:?(({$[("@"=*x)&^`I$1_x;1_x;`]}'L)^!T)^`
    C:(" "\"D&A D+A A-D D !D D-1 -D D-A D|A D+1 0 A !A A-1 -A A+1 -1 1")!0 2 7 12 13 14 15 19 21 31 42 48 49 50 51 55 58 63
    D:$`" "`M`D`MD`A`AM`AD`AMD
    J:$`" "`GT`EQ`GE`LT`NE`LE`MP
    B:{,/$(x#2)\y}
    P:{c:*d:|"="\*j:";"\x;"111",/(B.7,(64*|/"M"=c)+C@"A"/"M"\c;B.3,D??d 1;B.3,J??1_j 1)}
    `0:({(P;{"0"^-16$,/$2\(`I$1_x)^T@1_x})[2/"@"=*x;x]}'L)@&~i
Dyalog APL is the one I'm most familiar with; as well as its array language syntax it has procedural-style keywords for control flow[1] like if/then/else and do/loop and so on. It has OOP class syntax too, and .NET framework bindings for event-driven Windows Forms GUIs and calling C#/.NET DLLs or building APL-based DLLs for other .NET languages. So yes, but you're not writing much array style code to do those parts. As well as being usable for the back end of a webserver.

[1] https://help.dyalog.com/latest/#Language/Control%20Structure...

array languages are used by several companies for their work. K for example is pretty popular in fintech. Some present companies provide services for array languages as well.

https://www.dyalog.com/case-studies/index.htm https://github.com/interregna/arraylanguage-companies

Could you recommend a good starting episode? I know the generals of languages so I don't know if episode 1 is worth the time investment...
My favorite episodes were Stevan Apter, Leslie Goldsmith, Lib Gibson, Rob Pike and Jeremy Howard. If you want to go deep into the concepts focus on the tacit episodes or the ones with John Earnest or Aaron Hsu. There are transcripts with each episode so you can always read if your time is that valuable. https://www.arraycast.com/episodes

Full disclosure: I am on the ArrayCast

Thank you!! I have a long drive ahead of me today so this is very welcome.
Did you mean generals of array languages? I've only listened to the first 3 episodes so far and the Rob Pike episode[1] I mentioned. I have decades of experience in the popular programming languages and Lisp and some functional languages, but I'm new to array languages and I think I am the target audience.

If you're already experienced with array languages I'm not confident to recommend any particular episodes yet. You might find the Rob Pike/Ivy episode entertaining but maybe not informative. Rob is not an array language expert (he says this in the episode) but he made Ivy partly from nostalgia of APL in his early days. His recollection of that era I found good to listen to.

[1] https://www.arraycast.com/episodes/episode60-rob-pike