3
$\begingroup$

I've heard the explanation that functions like StringDrop[] are varargs and so that is why they do not have an operator form.

But when you are only using the single argument version, it seems well defined and quite ergonomic to me. Is there some other reason that operator forms like this aren't supported in the single argument case?

s = ImportString["./Arnold_Schwarzenegger 42
    ./George_W_Bush 530
    ./Jean_Chretien 55
    ./Jacques_Chirac 52", "Table"] // Dataset;
s[All, 1, StringDrop[#, 2] &] (* this works *)
s[All, 1, StringDrop[2]]      (* this doesn't work *)

enter image description here

Given the above example, the cited explanation is not clear, and I'm hoping a someone can comment.

$\endgroup$
  • 3
    $\begingroup$ This community cannot tell you why Wolfram Inc. made any design decisions. All we can say is "use the defined syntax." Since you know the defined syntax, what is the purpose of the question? $\endgroup$ – Bob Hanlon May 22 '17 at 17:14
  • 1
    $\begingroup$ @BobHanlon The community has developers so clearly it can, I've updated the question - the purpose is to understand this limitation better. $\endgroup$ – user5601 May 22 '17 at 17:27
2
$\begingroup$

We find that Drop and Take also lack an operator form. I believe this is because these functions have historically worked as identity when given a single argument, e.g. Take[{1, 2}] gives simply {1, 2}, and since the part specification of Take is often itself a List there is no way to differentiate reliably between a identity operation and an operator form.

I suspect that StringDrop and StringTake are simply following the syntax of Drop and Take in this regard in omitting an operator form, even though the nature of these functions makes the syntax unambiguous.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.