3 ms·
For a real eye opener compare the length of these K versions of the Alioth benchmarks to their more verbose brethren http://kparc.com/$/z/comp.k http://kparc.co
by swannodette 13y ago
For a real eye opener compare the length of these K versions of the Alioth benchmarks to their more verbose brethren http://kparc.com/$/z/comp.k http://kparc.com/$/z/comp.k.
I found these on the K OS project page - http://kparc.com/os.htm http://kparc.com/os.htm. There's a great description of Arthur Whitney building a Notepad like text editor (1K) in 30 minutes or so using this system here - http://coding-is-like-cooking.info/2013/09/an-introduction-to-array-languages/ http://coding-is-like-cooking.info/2013/09/an-introduction-t....
Personally K is a bit too terse for my tastes - I think something like Nile achieves some of the terseness of APL without looking like line noise - http://github.com/damelang/nile/blob/master/examples/text-layout.nl http://github.com/damelang/nile/blob/master/examples/text-la....
- fennecfoxen 13y agoa quick Internet also reveals: life:{3=a-x*4=a:2{+(0+':x)+1_x,0}/x}
- beagle3 13y agoExplantion: x is a 0/1 matrix of live cells. 0+':x -> "sum each element with one to the left (0 left of the first)" 1_x,0 -> "drop first, add zero at the end" (0+':x)+1_x,0 -> "sum each element with the one to the left and the one to the right (sum of previous expressions)" a:2{+...}/x -> "do that; transpose; do that; transpose again, and assign to a. 2{}/ means 'do twice'" At this point, "a" has the same shape of "x", but in every element is the sum of the elements of x from that location, one above, one below, one left, and one right. 4=a -> "1 where a=4, 0 otherwise" x*4=a -> "1 where x is 1 and a=4, 0 otherwise" a-x*4=a -> "decrease a from 4 to 3 if x=1 in the that place" 3=a-x*4=a -> "1 where one has 3 neighbours" So, if x is a 1/0 matrix "life x" does one iteration of Conway's game of life. And "1000 life/ x" would seek convergence or return to first state (but no more than 1000 iterations). There is code golfing here; It would have been purely readable K code if it wasn't golfed. But it would also have been two to three times as long.
- gruseom 13y agohttp://coding-is-like-cooking.info/2013/09/an-introduction-t.. http://coding-is-like-cooking.info/2013/09/an-introduction-t.... Thanks, I enjoyed that article. It gives a vivid picture of the gap between the array languages niche and mainstream programming culture.
- vorg 13y ago> Despite my head start with J, by the end of the conference I found APL code easier to grasp – J seems more extreme to me. Roger calls J “executable mathematical notation”, and I’ve always been a bit more of an engineer than a mathematician. I found this too, when I tried them both, first J then APL, perhaps because: * APL uses () [] and {} in their pairs to parenthesize things, just like other languages, while J uses the 6 symbols as standalones, harder to read the code. * All verbs in APL are single characters, whereas J symbols might be more than one. * J, unlike APL, uses the concepts of rank, and forks and hooks, which are both difficult to grasp and don't seem to add much to the array processing idea.