4 ms·
APL is a fascinating language -- it keeps popping up in odd corners like this, and there are echoes of APL in the design of a lot of popular libraries. Numpy i
by sevensor 10y ago
APL is a fascinating language -- it keeps popping up in odd corners like this, and there are echoes of APL in the design of a lot of popular libraries. Numpy is a good example: it's almost another language embedded in Python.
- ghosthamlet 10y agoagree with you, apl is great for ML, see this 6 lines Neural Network Example by apl with no deps: https://github.com/ghosthamlet/ann.apl https://github.com/ghosthamlet/ann.apl all code here: l0 ← 4 3 ⍴ 0 0 1 0 1 1 1 0 1 1 1 1 y ← 4 1 ⍴ 0 0 1 1 syn0 ← 3 1 ⍴ 0.5069797399 0.5703818579 0.9265880619 i ← 0 e ← 2.718281828459045 :While i < 10000 ⋄ i ← i + 1 ⋄ d ← l0 +.× syn0 ⋄ l1 ← 1 ÷ 1 + e * 0 - d ⋄ l1_err ← y - l1 ⋄ l1_delta ← l1_err × l1 × 1 - l1 ⋄ syn0 ← syn0 + (⍉ l0) +.× l1_delta ⋄ :EndWhile l1
- ghosthamlet 10y agoby the way, it is a ports from 11 lines python version here: http://iamtrask.github.io/2015/07/12/basic-python-network/ http://iamtrask.github.io/2015/07/12/basic-python-network/, isn't it more readable concise and beautiful than python version? if our all ML codes use apl, it will be a cool world.
- cwyers 10y ago> isn't it more readable concise and beautiful than python version? No.
- minimaxir 10y agoTo add to this, the which-loop-in-one-line-of-code is not self-documenting, which is important for data/ML in particular when others need to verify your code.
- cwyers 10y agoAnd it's not any shorter in terms of statements, they're just using the diamond operator to put all the statements in the loop on one line.
- klibertp 10y agoIt could simply be a badly written bit of APL. Although I don't know APL, I have some experience with J and I think the `:while` construct used here suggest more or less literal translation of the Python code.
- Sean1708 10y agoIs it possible to put that while loop on multiple lines? It looks like there are 6 different assignments in there, and trying to pick out what is happening is very hard when it's all on one line like that.
- Avshalom 10y agoYou can break it up at each diamond but then you'd need to wrap it in a function which would be harder to cut and paste into a repl
- rebootthesystem 10y agoHmmmm. This is a bad example of APL. Source: I used APL professionally for over ten years. For one thing, real APL does not have constructs like "while". That's the whole point of the language, to remove the need for the programmer to have to think this way. Also, this isn't, strictly speaking, six lines of code. The diamond is a statement separator. This is more like 15 or 20 lines (didn't count). Not that this is an important metric at all.
- sevensor 10y agoI'd be interested to know: for what kind of application did you use APL?
- rebootthesystem 10y agoQuite a range, actually. From business applications to robotics and DNA sequencing.
- agumonkey 10y agognu apl + emacs dyalog mode is a cute way to test
- sevensor 10y agoWhat font do you use for APL symbols?
- i_don_t_know 10y agoI've used this on the Mac: http://www.dyalog.com/apl-font-keyboard.htm http://www.dyalog.com/apl-font-keyboard.htm Font and keyboard settings work independently of Dyalog APL. (Thank you, btw, for that!) For example, I've used them with GNU APL.
- sndean 10y agoJust for the possible person using linux: the easiest way I've found to get that Dyalog font working is to install as it instructs you to, then run the bash script provided in this stackoverflow answer (http://stackoverflow.com/a/27955014/3430492 http://stackoverflow.com/a/27955014/3430492).
- agumonkey 10y agoemacs dyalog comes with a visual (textual) apl keyboard with the official symbols. There's also alternative bindings for more direct input.