@Adám I just did problems.tryapl.org 2017 problem 10, and when you get the correct answer, there's a sequence of numbers to the left of the congratulatory message. It says:
5 10 1 0 17 7 1 4 2 Passed all basic and edge cases – good job!
In clojure, we have something similar to scan, which is called reductions. But in this particular example, when I'm trying to use it to solve a problem, I can't explain why the following:
>\5 5 2
Is equal to 5 0 1.
But ... I will try to decrypt it with Adám's version above.
@Adám Yes, that makes it explicitly clear. I just have to wrap my head around it. Thank you and @FawnLocke as well for helping me walk through it. I'll work on it a bit more and hopefully internalize this.
The results of scan seem so obvious with +, and much less obvious to me in many of these other cases. I'm going to have to figure out how to get an intuitive grasp on it so I can solve problems with it.
@taronish APL's scan for things other than idioms is fun, but that's about all it has going for it. Definitely not a thing to really solve problems with, unless you're golfing
@dzaima Yes, I'm sure I don't have a sense yet of when to use it. This came up in the context of (tryapl) APL problem 2018 #1, where you're computing which skyscrapers you can see. So what I was trying to do was go over the list and find the places in the list where the value increased ...
But it didn't do quite what I expected and then I got sidetracked.
i dont even know what it'd mean in python... like idk what it'd mean there... wait ok i googled... the definition isn't precise... "Pertaining or conforming to the natural mode of expression of a language"
You may see someone say "using eval() isn't idiomatic." meaning it's a bad practice. In APL we use both "idiomatic", to mean the same as Pythoners and "idioms" to refer to short functions composing something more meaningful.
I'm working on (tryapl) problem 2018 #3 ... I understand the concept, but I'm at bit of a loss for how to produce the exact output the system is looking for.
My best effort is:
{⎕IO←0⋄⍕{⍺ ((≢⍵)⍴'*')}⌸,⊃∘.+/1+⍳¨⍵}
But that differs by minor spacing and by the mixed array vs non-mixed array.
What is the intended way (maybe just a way I've written the left parameter of key incorrectly?) to get exactly the output that is desired?
It wouldn't be a matrix, because the definition of a matrix is that its shape is a 2-element vector.
Actually, now I think about it, many popular programming languages "restrict" "⍴" to a scalar left argument, i.e. they can only express/handle/manipulate lists of lists of lists… APL expands this so ⍴ can take a vector left argument, giving us multi-dimensional arrays. Maybe it would be possible to have a programming language that expands ⍴ to matrix left arguments, giving access to hyper-dimensional arrays?
@dzaima yea ik. i said that's how i imagine it. ofcorse idk how useful it'd be but theoretically the way symbols work on them would be diffrent... doesnt make sense yet
yea definetly. it should have some kind of use. tho maybe you don't need to redisign everything. maybe it'd just be some kind of imaginary number math somehow ¯\_(ツ)_/¯
@FawnLocke I'd say "All functions can be called either with a single argument (monadically), or two arguments (dyadically)" as not all functions have both meanings (if errors are excluded from being a "meaning"); bad comma in "Scalars, have"; unmatched quotes in "⍳n'
@Adám I remember having discussions about how assignment sometimes having and sometimes not having implicit each is bad
@Adám you have to decide whether or not to scalar extend somewhere. For both cases, the input to the left operand is an array of numbers, so you can't decide anything based on that. So you have to decide it per function in the right operand
a←⍳¨⍳4 ⋄ (⊃a)←1 2 ⋄ a
┌───┬───┬─────┬───────┐
│1 2│1 2│1 2 3│1 2 3 4│
└───┴───┴─────┴───────┘
a←⍳¨⍳4 ⋄ (1↑⊃a)←1 2 ⋄ a ⍝ 1↑ is a noop as `⊃a` already has length 1
LENGTH ERROR
a←⍳¨⍳4 ⋄ (1↑⊃a)←1 2 ⋄ a
∧
Hi all. The main project I'm working on presently is very statistics oriented. As such, plotting becomes important. The ]plot command is pretty limited and I don't see a way to use it from within a function. It appears that SharpPlot is not available for macos. I got pynapl to try to use matplotlib from python. pynapl seems to work, but I'm having difficulty figuring out how to get it to work with apl data.
@Adám Yes, it works. I'm probably being dumb, but the only way I could see the chart was to assign the value of sp.RenderSvg... to a variable, write to file using ⎕NPUT, then opening that file. I see in the cultivation on simple plotting a function called View. Is that Causeway.View? I get an error
InitCauseway ⍬ sp←⎕NEW Causeway.SharpPlot sp.DrawLineGraph ⊂3 1 4 1 5 svg←sp.RenderSvg Causeway.SvgMode.FixedAspect 'h'⎕WC'HtmlRenderer'svg LIMIT ERROR: The object could not be created 'h'⎕WC'HtmlRenderer'svg ∧
what is the most efficient way to count to a billion? python does it in 54 seconds, javascript in 6 seconds (with my code). i did x←0⋄({x+←1}⍣1E8) 1 and it's literally taking about 43 seconds to count only to 100 mil instead of a bil... because yea i got bored. why is this? maybe i'm looping wrong?
i guess it kinda makes sense given that this is all the assembly from the two functions taking part in executing +⍟n: https://dzaima.github.io/paste/#0jZPNboJAEMfvPsUc20o2uwsoePZea5r0YEwDy5piQChLDX2B3tu@YZ@kIyuw6tZ0DwRmfvOfL3YhKyF3NRzPCE7P1e95qiKlZB5n71BsQElRp8UOSC2benYReWKoZCmj@lnwm9sLkhBiNzHCA4DJlM7QlBf7XixJnYen@@UcFo9LWFWqHNMmWJ@LmBEqdSrmIUEJm1qJpEGCjyDwCZ0cjT8fXyCiLDt@mjmZjzkZXbeSfGKVZNypoua8rESKnohLnDBzCXf7jJ@w3ckOwN7hn@M6sUVJomd9kPfIhHaO8k29dMnb0nAerlF7FCvtFI2D/W2MI1uaWukQYZNNNOt1bCYjc3krlB/jTu74YX6chK4NxBI0mDQapMQNO6/IS1OxCrFRRljQjfEbtnE/RlfAlXDMcwg3ji2cceL1Ze6x@Vf92uQ5dbCXNoHn2wnmYB…