« first day (1300 days earlier)      last day (1355 days later) » 

12:54 AM
So the footer has f←⍎⊃⍬⍴¯3↑⎕SRC⎕THIS
I can understand most of the symbols by themselves, but not exactly that they are doing here with an anonymous function
@Adám are we basically passing the argument as a vector tho the function above?
⎕ is used for evaluating the expressions in the input, right?
 
(It's 2am in the UK and Adám is likely asleep); ⍎ is for evaluating expressions, ⎕src and ⎕this are their own tokens
from Dyalog's help, "⎕THIS returns a reference to the current namespace" and "⎕SRC returns the script that defines the scripted object Y", then ¯3↑ is taking the last 3 lines of the source code script, and doing something to them, then running them and storing the result in f..? No clue what ⍬⍴ does
 
ngn
1:33 AM
@Razetime it's a hack to extract the code from tio's "code" section and assign it to f for testing purposes
 
ngn
1:44 AM
does anyone have a clue why this is a syntax error?
 
1:57 AM
@TessellatingHeckler Thanks a lot!
@ngn so this is for testing functions
 
@ngn probably was a bug (happens in 17.1, doesn't in 18.0)
@ngn replacing ⌊⌿ with {⍺⌊⌿⍵} fixes it
 
 
2 hours later…
4:09 AM
@TessellatingHeckler @Razetime ⍬⍴ reshapes to a scalar, i.e. gets the first element, i.e. the third last. The idea is that the SouRCe says:
:Namespace
    {⍵=0:¯1 ⋄ ⌊2⍟⍵}
    f←⍎⊃⍬⍴¯3↑⎕SRC⎕THIS
:EndNamespace
So we get the third-last line, execute it (which returns the function) and assigns it to f which can then be used in the interactive session ("REPL") labelled "Input" on TIO.
Why didn't I use 3⊃⌽ instead of ⊃⍬⍴¯3↑? because the code above it may set ⎕IO←0 (index origin 0 ― the 3 would be off-by-one). Why didn't I use ⊃¯3⌽ instead of ⊃⍬⍴¯3↑? Because the code above it may set ⎕ML (migration level ― the would be Mix instead of First).
@Razetime It is a hack for keeping the actual code in "Code" but doing the assignment to f outside "Code", namely in the Footer. I simply accomplishes being able to create a named function without counting the naming in the character count. If we had line continuation (e.g. a trailing backtick) I might have written f←` in the "Header" instead.
 
4:33 AM
interesting
so I'll have to modify this snippet per question
 
@Razetime You only ever need to change the "Code" and "Input" parts. The "Footer" is universal.
 
Great to know.
 
Oh, and if you ever need some set-up before your code runs (and which shouldn't be counted as part of your code), you can put that in the "Header". Examples would be ⎕IO←0 or creating a file, importing a library, etc.
 
 
3 hours later…
ngn
7:57 AM
@dzaima oh, i see. thanks.
 
8:19 AM
@Adám in your style guide you say Avoid relying on errors if at all possible -- what does this mean? No error guards?
Or don't rely on error guards for flow control?
 
8:58 AM
@xpqz Right, don't do e.g. {11::'NaN' ⋄ ⍺×÷⍵} but rather {0=⍵:'NaN' ⋄ ⍺×÷⍵} or {×|⍵:⍺×÷⍵ ⋄ 'NaN'}. Same thing applies to :Trap and ⎕TRAP.
 
I've found myself on occasion doing 3::⍺ for expected recursion termination instead of doing a bounds check -- would you consider this bad form?
Definitely a Python hangover -- try ... except IndexError
 
@xpqz I would. Errors cause the flow to jump, and cannot safely be predicted. If I trace through a function, I can assume that each expression will be followed by the next. When I reach a guard, I can pre-execute the condition to predict what will happen next. However, I can't easily predict when an error will happen, and when it does, execution (and for dfns: state) can go anywhere up the stack, causing loss of situational awareness.
 
Ok, I shall have a word with myself about my laziness.
 
@xpqz Here, compare these two functions:
 F1←{
     11::nums
     nums←1 ⍺
     nums×÷⍵
 }
F2←{
     nums←1 ⍺
     0∊nums:nums
     nums×÷⍵
 }
@xpqz Do you see the bug in F1?
 
9:15 AM
Eh, guessing: nums←1 ⍺ can also throw an 11? Somehow?
 
@xpqz No it cannot. 11 is domain error. If is not defined, it'll give 6 (value error).
Try running 4 F2 0 and then 4 F1 0.
 
F2 catches the divide by zero.
 
F2 pre-empts the divide by zero and correctly returns nums. F1 catches the divide by zero, but what happens when it does that?
 
Hmm -- not sure what the wanted behaviour is. I get:
4 F2 0
DOMAIN ERROR: Divide by zero
 
Ah man, I messed up. Sorry.
F2←{
     nums←1 ⍺
     0=⍵:nums
     nums×÷⍵
 }
 
9:24 AM
Is F1 as it should?
4 F1 0
1 4
 
Uh, I don't get that from 4 F1 0
 
      4 F1 0
VALUE ERROR: Undefined name: nums
F1[1] 11::nums
wtf..
 
Yup. Why?
 
I swear that worked the first time I ran it.
Local environment is unwound before body of error guard is evaluated.
This I had no idea about until I just read it in the docs.
That seems like a rich seam of hard to find bugs for the uninitiated.
Ah -- and now I do understand why the first time I ran it it worked: I ran that inside the debugger had paused on the div-by-zero error in the faulty F2, so the nums variable was present in the environment.
So you can't realiably use anything defined inside a dfn in the body of an error guard. I've not shot myself in the foot with this gun yet, only by luck.
I also see in the docs: Following the setting of an error-guard, subsequent function calls will disable tail call optimisation
Ouch.
Thinking about it, I guess that it has to be that way.
TCO removes the call stack.
 
9:40 AM
So, now you understand my style guide.
 
Yes, but that's a super important point that is only superficially about style perhaps.
 
OK, maybe "style" isn't the right word. Coding guide is maybe better.
 
Best practices?
Anyway - thanks for the lesson master yoda
 
Mastering Dyalog APL, you will be.
Besides for the pitfalls of dfn error guards, it is also hard to know which error guard will fire. It could be anywhere up the stack.
 
Ok, error guards are absolutely not behaving like python exceptions -- that is a very useful takeaway for me.
 
9:49 AM
You might find that tradfns' :Trap has a saner behaviour.
What does the following function return?
 F3←{
     5::'two vs three'
     11::'cannot add characters'
     'ab'+1 2 3
 }
Compare:
F4←{
     5::(⍕≢⍺),' vs ',(⍕≢⍵)
     11::'only numbers allowed'
     ⍺+⍵
 }
F5←{
     (≠/≥1∘∊)≢¨⍺ ⍵:(⍕≢⍺),' vs ',(⍕≢⍵)
     ~1|⎕DR∊⍺ ⍵:'only numbers allowed'
     ⍺+⍵
 }
 
Not sure what I'm looking at -- they all seem to do the same thing?
      F3⍬
two vs three
      'ab' F4 1 2 3
2 vs 3
      'ab' F5 1 2 3
2 vs 3
      1 2 3 F5 'abc'
3 vs 3
      1 2 3 F4 'abc'
only numbers allowed
Is F5 correct? I assume the wanted behaviour is that of F4? First check the number of elements, then the 'numberness'?
 
10:05 AM
@xpqz Ah, but that's the point. F4 doesn't (explicitly) check one issue after the other, so you cannot predict which issue will be caught. In F5 you know perfectly well that you're checking for the length error first, and only then for the domain error.
Even worse: (5 6⍴1)×2 3 4⍴'A' ― what will happen? RANK or LENGTH or DOMAIN?
If you check, instead of letting the interpreter check, then you know exactly what will happen.
 
Hang on.
If that's the case, then why isn't this a DOMAIN?
1 2 3 F5 'abc'
3 vs 3
Ah
 
Because I got my logic wrong :-)
 
The guard only checks ⍺
No.. eh
 
It should have said (≠/>1∘∊)≢¨
That isn't actually important, though. ≠/≢¨⍺ ⍵ would have been clear enough in this case. I just wanted to (but miserably failed) to allow the case when one side has length 1.
 
10:23 AM
Ok - reading some more docs.
Another line from your style guide I didn't fully understand was Never use inline assignments that prevent re-executing the line if it errors when partially executed. Is there a simple example of this you can show?
 
ngn
i searched aplcart for "aes" and it offered me the "caesar cypher" [sic] - lol :)
 
10:42 AM
@ngn Uh, wherein lies the error to which you remark "[sic]"?
 
ngn
@Adám cipher
 
21
A: Cipher vs. Cypher

Barrie EnglandThe Oxford Dictionary gives both cipher and cypher in that order. The preference for cipher over cypher seems to be a little greater in American English than in British English. The Corpus of Contemporary American English has just over three times as many records for cipher than it has for cyphe...

 
ngn
ugh, i've never seen it written that way
 
cypher just looks wrong to me
'In academia 'cipher' seems to be the popular choice even when the rest of a text adheres to British English spelling, though.' I definitely agree with this comment
 
ngn
the funny thing is it "understood" aes has something to do with crypto. nice coincidence :)
 
10:44 AM
Well no, cAESar
 
Notice the conclusion of the accepted post:
> It would not occur to me, as a speaker of British English, to use anything other than cypher.
 
speaker of British English != cryptographer
 
ngn
it's like dialog/dialogue or program/programme
 
Not really. Those have clearly had their silent French ending chopped, while cipher/cypher is due to a historic i=y combined with the great vowel shift, and maybe influence from other things like tire/tyre even though etymologically, it should be an i.
 
ngn
@Adám i mean, afaik dyalog docs use BrE in general, but if there's an established AmE technical term for something, they use the popular spelling. better ask your documentation manager.
 
10:51 AM
@ngn That's me. (APLcart isn't a Dyalog product.) But I'll change it to chipher and make cypher a synonym. Should I also add Cesar as a synonym to Caesar?
 
ngn
@Adám i have no problem with "caesar"
 
nah doubt anyone uses that
 
 
5 hours later…
3:53 PM
@chv Shalom. Interested in APL?
 
4:48 PM
Found an interesting bug in APL, paste
next ← ⊃(1,⊂)∨.∧∘(3 4=((+/+⌿)1 0 ¯1∘.⊖1 0 ¯1⌽¨⊂))⊢
and then do ]defs
it has 'simplified' the expression and removed a pair of parentheses, giving back
next ← ⊃(1,⊂)∨.∧∘(3 4=(+/+⌿)1 0 ¯1∘.⊖1 0 ¯1⌽¨⊂)⊢
but causes the definition to break
 
5:01 PM
@rak1507 simpler example: next ← -(÷×)
 
ngn
@rak1507 what do you type to use ]defs ? with no args i get a value error
 
@ngn it just works (at least on 18.0)
 
^
 
ngn
even after rm -rf ~/.dyalog:
Dyalog APL/S-64 Version 18.0.38525
Serial number: UNREGISTERED - not for commercial use
+-----------------------------------------------------------------+
| Dyalog is free for non-commercial use but is not free software. |
| A non-commercial licence can be used for experiments and        |
| proof of concept until the point in time that it is of value.   |
| For further information visit                                   |
| dyalog.com/prices-and-licences.htm                  |
+-----------------------------------------------------------------+
 
maybe that's another bug
 
5:17 PM
@ngn huh, through my exploration i got that 0 1 ⎕SE.SALTUtils.Spice 'box' works, but 0 1 ⎕SE.SALTUtils.Spice 'defs' doesn't. ¯\_(ツ)_/¯
(no clue why that's the case, because that's exactly what ⎕SE.UCMD executes)
 
5:43 PM
@dzaima No it isn't. The interpreter calls ⎕SE.UCMD with a left argument which is the namespace where ] was entered.
@rak1507 Yes, the ]defs (and ]box -trains=def) user command tries to remove unnecessary parentheses, but John Scholes was still developing it when he died. He never removed the last bugs:
      ]box -t=def
Was -trains=tree
      (⊢∘1)(2∘⊢)
⊢∘1 2∘⊢
 
Is there a keyboard shortcut to end execution of an infinitely running function? Accidentally just used the fixpoint operator with something that never terminates, oops
 
@rak1507 Forgive for forgetting, what RIDE or Windows IDE?
 
dyalog on windows
 
Ctrl+Break (Pause) or SysTray→Dyalog logo→Strong interrupt.
 
You are a life saver thanks! Now I haven't lost all my progress
 
5:53 PM
I'm here all week ;-)
 
ngn
that's why you should write code in files
 
I am very lazy
 
@ngn Can't agree more.
@rak1507 It is quite easy to get started with code in files.
 
Well now I know ctrl + pause exists there's no need ;)
 
One day, you might have a power cut or see the interpreter crash, and you'll wish you used code in files.
 
6:15 PM
@dzaima ≢>3‿0⥊⟨⟩ gives ⟨0⟩. Not the answer I was expecting...
 
@Marshall i'm lazy
 
@dzaima But returning x is shorter!
 
@Marshall i'd have to reconstruct the x, it's passed as the Value[] and shape separately
(it's still a rather simple new EmptyArr(sh, null) but still)
 
@dzaima So I guess the condition in call() should be x instanceof Arr && x.ia>0 && !x.quickDepth1(). Which does end up shorter but arguably isn't lazier.
 
@Marshall one of the fun times i get to try to merge the equal return x;s by just IDEA refactorings :p
so now i have to special-case things like +⎉2˜0‿0‿0‿0⥊⟨⟩ (there are 12 usages of merge, and most probably can probably give empty arrays)
@dzaima actually no, special-casing it doesn't make sense, since the function could be non-scalar
 
6:30 PM
@dzaima Yeah, there you have to do a type computation to get the real result shape.
 
@Marshall which in general is the same problem as getting the shape of >3‿0⥊⟨⟩
 
@dzaima Yes.
 
@dzaima ≢∧0‿0⥊⟨⟩ (& ) and ˘ seem to be the only other affected things
 
@dzaima For sorting you should just be able to do something like {(⍋<˘𝕩)⊏𝕩} instead of {>∧<˘𝕩}, which I assume is the problem.
 
@Marshall my should be way slower than >Arrays.sort(<˘𝕩), and it's much simpler to just check for an empty array argument anyways
 
6:49 PM
@dzaima Fair. For arrays with large cells you'll want to do anyway to avoid the data movement, but lists are probably a lot more common.
 
@dzaima also ⍷0‿0‿0⥊1
what should ≢⍷0‿0⥊1 (vs ≢⍷4‿0⥊1) be?
 
@dzaima 0‿0 and 1‿0 respectively. of a length-0 (or 1) array is always the identity, and empty cells match.
 
pushed changes
 
7:12 PM
@dzaima Now <˘ 2‿0⥊⟨⟩ is giving a strange result: its shape is ⟨2⟩, but it prints as ⟨⟩.
 
@Marshall right, need to check that cells are empty , not the whole array is
hopefully fixed
 
@dzaima That works. I don't have to patch couple.html any more!
 
chv
7:53 PM
@Adám just Wandering around.. thank you
 

« first day (1300 days earlier)      last day (1355 days later) »