Dyalog / link

Source code for Link – the built-in component that enables the use of text files as the primary storage mechanism for APL source code
https://dyalog.github.io/link
MIT License
19 stars 10 forks source link

Enhancement: make ]link.add and friends allow multiple names #194

Closed bernecky closed 3 years ago

bernecky commented 3 years ago

Life is too short for: ]add this ]add that ]add them

I want: ]add this that them

bernecky commented 3 years ago

Also, I want to be able to add all the elements of a folder F by doing:

]add F

or something along those lines

bernecky commented 3 years ago

So, I discovered ⎕se.Link. It doesn't work so hot if you make a typo:

     )cs fragments
#.sac.fragments
      ⎕this
#.sac.fragments
      ⎕SE.Link.add ⎕NL 2
VALUE ERROR: Undefined name: add
      ⎕SE.Link.add ⎕NL 2
               ∧
      ⎕this
#.sac
abrudz commented 3 years ago

I don't remember why there's this restriction, but meanwhile, simply use ⎕SE.Link.Add 'this' 'that' 'them'.

I'm not sure what you mean by adding all the elements of a folder. You're using Add, which means you're on the APL side of the linkage, and APL doesn't have "folders". Do you mean to add a namespace that you've created? That should work. If it doesn't, then please log a separate issue for that. If instead you mean to add all the members of a particular namespace, then maybe ⎕CS F ⋄ ⎕SE.Link.Add ⎕NL-⍳9 might help.

abrudz commented 3 years ago

Yes, APL code is case-sensitive, similar to how Linux deals with file names. On the other hand, both system commands and user commands have always been case insensitive, similar to how Windows deals with file names.

Was this a good design? Maybe not. But it was made many decades ago, and would b difficult to change at this point.

bernecky commented 3 years ago

Add only likes vectors, it seems, and not even all of them. Rank to the rescue, of course!

    ⎕se.Link.Add (,' ',⎕NL 2)
Not found: #.sac.fragments.TEMPcatlamTEMPcommandlineTEMPcutTEMPdadverbsTEMPdconjTEMPdgradeTEMPdmiscTEMPdscalarTEMPdsfctlTEMPds
      tructTEMPepioTEMPindrTEMPindsTEMPjotdotTEMPmadverbsTEMPmconjTEMPmdrankTEMPmgradeTEMPmmiscTEMPmscalarTEMPmsfctlTEMPmstruc
      tTEMPquadfiTEMPqueryTEMPquotequadTEMPreplicateTEMPreshapeTEMPscanTEMPsysfnsniladicTEMPtakedropTEMPthornTEMPutilities
      ⎕se.Link.Add ⎕NL 2
Not found: #.sac.fragments.TEMPcatlamTEMPcommandlineTEMPcutTEMPdadverbsTEMPdconjTEMPdgradeTEMPdmiscTEMPdscalarTEMPdsfctlTEMPds
      tructTEMPepioTEMPindrTEMPindsTEMPjotdotTEMPmadverbsTEMPmconjTEMPmdrankTEMPmgradeTEMPmmiscTEMPmscalarTEMPmsfctlTEMPmstruc
      tTEMPquadfiTEMPqueryTEMPquotequadTEMPreplicateTEMPreshapeTEMPscanTEMPsysfnsniladicTEMPtakedropTEMPthornTE
      ⎕se.Link.Add⍤1⊣ ⎕NL 2
Added: #.sac.fragments.TEMPcatlam       
Added: #.sac.fragments.TEMPcommandline 
...
abrudz commented 3 years ago

Are you aware of ⎕NL with negative numbers? If one or more of the argument elements is negative, then ⎕NL returns a vector of character vectors. That said, we should probably always accept a name matrix in place of a name list.

bernecky commented 3 years ago
  1. The API docn for ]link.add refers to something called an "items". What is it, and where is "items" defined? Being precise, rather than vague, is important in technical writing, as it saves time for both the author AND the user.

  2. Are you aware that the above code example failures change the current namespace? I do prefer case sensitivity, but it should not come at the cost of changing the execution environment without warning.

  3. Life is too short to remember ill-designed things like ⎕nl with negative numbers.

abrudz commented 3 years ago
  1. I'm not sure which API documentation you refer to. If you refer to this then I'd expect a reader to follow the link to see the full description here, which I think is clear enough.
  2. I didn't notice, but I can't reproduce it either:
        )clear
    clear ws
        )ns sac.fragments
    #.sac.fragments
        )cs sac.fragments
    #.sac.fragments
        ⎕this
    #.sac.fragments
        ⎕SE.Link.add ⎕NL 2
    VALUE ERROR: Undefined name: add
        ⎕SE.Link.add ⎕NL 2
                 ∧
        ⎕this
    #.sac.fragments
  3. You're right ― APL should have had nested arrays from the beginning. That said, do you know about the Split primitive, monadic ? With it, ↓⎕NL 2 should give you a vector of names (though with trailing spaces, of course).
bernecky commented 3 years ago

Re the above unannounced namespace change, it looks worse than I thought:


    )cs fragments
#.sac.fragments
      ⎕this 
#.sac.fragments
      ⍴xx
32 17
      ⍴yy
34 13
      xx,yy
LENGTH ERROR
      xx,yy
        ∧
      ⎕this
#.sac

This workspace does not use ⎕trap, so I find this behavior a trifle odd. Ideas welcome. I'll delve further, meanwhile.

abrudz commented 3 years ago

This is clearly not a Link issue. If you can write a complete repro of the issue starting with a clear workspace, then please email that to support@dyalog.com ― don't forget to include the output from ]version

nicolas-dyalog commented 3 years ago

⎕SE.Link.Add does work with multiple names. However I agree with Bob that ]link.add should allow multiple names too.

abrudz commented 3 years ago

While I tend to dislike special cases, maybe handing ]add ⎕NL followed by an expression consisting of the characters ¯-0123456789.⍳ would be a good idea. Note that no APL name can ever consist entirely of those characters, so this doesn't block anything.

nicolas-dyalog commented 3 years ago

Fixed in link v2.1.0-beta26:

Please report one bug per issue. Here you have reported several.