7 ms·
Fun fact: All three of Go's creators have written APL interpreters, and Go's "iota" keyword is modeled after the corresponding APL operator.
by nemo1618 8y ago
Fun fact: All three of Go's creators have written APL interpreters, and Go's "iota" keyword is modeled after the corresponding APL operator.
- boomlinde 8y agoI wouldn't say that Go iota is modeled after APL iota. They share the same name, but that's really where the similarities end. The iota operator in APL is more like the unary case of the python range function.
- nemo1618 8y agoThey are both used to generate a sequence of consecutive integers, although Go's iota starts at 0 whereas APL's starts at 1. "Ken suggested iota for the counter and, since all three of us (Ken, Robert, Rob) had implemented APL interpreters, it seemed a perfect thing to us." - Rob Pike
- ceautery 8y agoI think iota in APL can start at zero if you set the index origin (⎕IO) to 0.
- 4thaccount 8y agoYes it can. I ran into an issue with one of the APL examples once because the index had been changed and it wasn't documented. The Dyalog folks answered my email on the weekend (I'm not a customer).
- kbenson 8y agoThat sounds like one of those super useful features that's easy to shoot yourself in the foot with. Perl has a few of those (cribbed from AWK, I believe): $, : The output field separator $ perl -E 'my @data = (11,22,33); say 11,22,33; say "@data"; say @data; $,="|"; say 11,22,33; say "@data"; say @data;' 112233 11 22 33 112233 11|22|33 11 22 33 11|22|33 $" : Interpolated list separator $ perl -E 'my @data = (11,22,33); say 11,22,33; say "@data"; say @data; $"="|"; say 11,22,33; say "@data"; say @data;' 112233 11 22 33 112233 112233 11|22|33 112233 And a bunch more, including input line/record separators (so you can slurp a whole file into a buffer at once instead of line by line), etc.
- boomlinde 8y ago> They are both used to generate a sequence of consecutive integers, although Go's iota starts at 0 whereas APL's starts at 1. Iota in APL is unary operator that generates a vector of consecutive integers starting at the origin up to and including its operand. Iota in Go is a predeclared identifier that can only be used in constant declarations wherein it auto-increments on every use. The resemblance is superficial at best. > "Ken suggested iota for the counter and, since all three of us (Ken, Robert, Rob) had implemented APL interpreters, it seemed a perfect thing to us." - Rob Pike Maybe we have just have a different view on what "modeled" means, or I am being too literal. To me, "modeling" implies that something is created with another thing in mind, adhering to the same principles. To relate that to the quote, I wouldn't call the process of coming up with a concept and only afterwards finding a name for it from some handwavely similar concept in another context modeling.
- nemo1618 8y agoNo, I think your criticism is fair. "Modeled" is not quite accurate, since the term was applied retroactively to functionality that was already implemented. Still, I wouldn't call the resemblance superficial. "iota" in both languages refers to sequences of whole numbers. If "iota" in Go meant "the zero-value for an arbitrary object" or "the smallest non-zero float64," then the two would truly share only a name.
- boomlinde 8y agoIf there are more than superficial similarities between the two, surely there is a rough analogue for "⍳10" in Go using its iota. Conversely there must be an analogue for "const ( A = iota; B; C )" in APL using its iota. Those are the fundamental uses of these entirely (IMO) different concepts. In the latter case, you can say that "A B C←⍳3" (at least in Dyalog) which is roughly equivalent to a Go constant assignment using iota if you squint a little and disregard the underlying procedure of creating and unpacking an array at run-time vs creating a compile-time constant. In the former case, I'm not aware of any analogue.
- kasbah 8y agoRob Pike also implemented an APL-like big number calculator in Go more recently: https://github.com/robpike/ivy https://github.com/robpike/ivy >The author has never used APL. It's a chicken and egg problem. (...) All testing has been done with tryapl.org. There are also a few free software implementations of APL most notably GNU APL. I have been sticking to that while learning APL. https://www.gnu.org/software/apl/ https://www.gnu.org/software/apl/
- threwawasy1228 8y agoI've personally found GNU APL to be a bit flimsy, and not some of the design choices they made in it to be a bit odd. It also deviates from the ISO standard, if that matters to you. Dyalog is the only implementation that is robust and production ready that is still actively maintained. I would suggest learning with something other than the GNU implementation.
- kasbah 8y agoI am learning using the book "APL with a Mathematical Accent" and so far all the examples work fine (I am on chapter 3). I'll probably switch to learning J if I start running into problems. It says on the GNU page "implementation of ISO standard 13751" so if it's not standards compliant it should likely be filed as a bug. I did request a copy of Dyalog but they rejected my application (probably because I didn't add my address?). I don't have a lot of enthusiasm for learning using a proprietary implementation of a language anyway.
- threwawasy1228 8y agoI'm not sure where you are seeing that, on the GNU page I'm looking at[0] they are very clear that they are not following the complete standard. "The APL interpreter is an (almost) complete implementation of ISO standard 13751 aka. Programming Language APL, Extended." [0] https://www.gnu.org/software/apl/ https://www.gnu.org/software/apl/
- 8y ago
- 3xblah 8y agoOf course it takes less time and effort to write an APL interpreter than it does to actually learn APL. I wish there were more languages like that.
- segmondy 8y agoEvery programmer should implement 6 languages assembler, basic, c, lisp, prolog & APL.
- 4thaccount 8y agoForth?