scripting: numbered arguments QA

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

scripting: numbered arguments QA

Post by bdeshi »

Saw this in the changelog today:

Code: Select all

[..] the flag bit "2" has to be set [...]
 
popupmenu(":copypath|:dp|:pp", 5:=2);
"5:=2"? What is this never-seen-before syntax?

Code: Select all

popupmenu(itemlist, x, y, start, count, flags, sep_itemlist, sep_item, on_cancel)
          0         1  2  3      4      5
Aha!
So, now we can skip a number of parameters of a function: define a new starting point for indexing parameters, and continue from there.

But apparently this can be used only once in a function definition and everything else afterwards is forcibly ignored.

Code: Select all

//replace(string,      search, replacement, matchcase, start, count)
//        0            1       2            3          4      5  
  replace("XabXcdXef", "X",    "|",                    4:=2,  1    );
  replace("XabXcdXef", "X",    "|",                    4:=2,  5:=1 );
Here 4:=2 skips 3:matchcase and defines 4:start as 2, but then following param count is not set to 1.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Undocumented script commands - Suggestions

Post by PeterH »

I'm not convinced that

Code: Select all

  replace("XabXcdXef", "X",    "|",                    4:=2,  1    );
is allowed in the moment.

But I think your idea isn't bad, i.e. a positional operand following a numbered operand should mean the operand with the previous number plus 1.

I'm afraid I searched documentation for this some days ago and didn't find it, too :(
(Though I remember I've read this in some thread...)

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Undocumented script commands - Suggestions

Post by bdeshi »

PeterH wrote:I'm not convinced that

Code: Select all

  replace("XabXcdXef", "X",    "|",                    4:=2,  1    );
is allowed in the moment.
No, it is.

Code: Select all

// param 4 is starting point
  echo replace("XabXcdXef", "X", "|", 4:=1); // |ab|cd|ef
  echo replace("XabXcdXef", "X", "|", 4:=2); // Xab|cd|ef
  echo replace("XabXcdXef", "X", "|", 4:=5); // XabXcd|ef
// param 5 is replacement count
  echo replace("XabXcdXef", "X", "|", 5:=1); // |abXcdXef
  echo replace("XabXcdXef", "X", "|", 5:=2); // |ab|cdXef
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66730
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Undocumented script commands - Suggestions

Post by admin »

Searching the change log for ":=" would have taken you 10 seconds to find this. :P

Code: Select all

v17.30.0001 - 2016-11-02 11:29
...
  +++ Scripting: Now numbered arguments are supported. Instead of counting 
      commas you now can prefix the position of the argument to the argument 
      itself. The separator is ":=", the first position is 0 (zero).
      For example, instead of this:
        text popupmenu("A,B,C", , , , , , ",");
      You now can do this:
        text popupmenu("A,B,C", 6:=",");
      You can even do this (reversed or chaotic order):
        text popupmenu(6:=",", 0:="A,B,C");
      Or this (processing is from left to right, the last mapping wins):
        text popupmenu("a,b", 6:=";", 6:="|", 6:=",", 0:="A,B,C");
It's also in the Help file under Scripting / General Command Syntax / Numbered Arguments.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Undocumented script commands - Suggestions

Post by bdeshi »

gah!

Still, why doesn't these work as expected?

Code: Select all

::echo replace("XabXcdXefXgh", "X", "|", 4:=2, 5:=1); // should be Xab|cdXef, but gives Xab|cd|ef
::echo gpc(<xypath>, 1:='file'); // should be XYplorer.exe, instead gives <xypath>
interestingly, these return correctly:

Code: Select all

::echo gpc(<xy>,, 1:='file');
::echo replace("XabXcdXefXgh", "X", "|",,, 4:=2, 5:=1);
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Undocumented script commands - Suggestions

Post by PeterH »

SammaySarkar wrote:No, it is.
Ouh - misunderstanding.
I didn't mean the numbered operand - I meant the unnumbered operand following a numbered operand.

admin wrote:Searching the change log for ":=" would have taken you 10 seconds to find this. :P
I was searching for the syntax - so I didn't remember it was ":="
Sad to say: didn't find it in Help, too. Maybe I was a bit blind :ghost:

You said nothing to the current problem, and help also doesn't seem to do: an unnumbered operand follows a numbered operand, as in above examples. Is this allowed, and what are the rules?

admin
Site Admin
Posts: 66730
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Undocumented script commands - Suggestions

Post by admin »

SammaySarkar wrote:gah!

Still, why doesn't these work as expected?

Code: Select all

::echo replace("XabXcdXefXgh", "X", "|", 4:=2, 5:=1); // should be Xab|cdXef, but gives Xab|cd|ef
::echo gpc(<xypath>, 1:='file'); // should be XYplorer.exe, instead gives <xypath>
interestingly, these return correctly:

Code: Select all

::echo gpc(<xy>,, 1:='file');
::echo replace("XabXcdXefXgh", "X", "|",,, 4:=2, 5:=1);
Bug confirmed! :bug: Fix coming...

admin
Site Admin
Posts: 66730
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Undocumented script commands - Suggestions

Post by admin »

PeterH wrote:I'm not convinced that

Code: Select all

  replace("XabXcdXef", "X",    "|",                    4:=2,  1    );
is allowed in the moment.
It is allowed but I would not recommend it since it is difficult to process for the brain what will happen. In the above case , the last "1" will actually overwrite the previous "4:=2", since both refer to the argument at position 4 but the last definition wins.
PeterH wrote:But I think your idea isn't bad, i.e. a positional operand following a numbered operand should mean the operand with the previous number plus 1.
This is definitely not supported at the moment.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Undocumented script commands - Suggestions

Post by PeterH »

admin wrote:
PeterH wrote:I'm not convinced that

Code: Select all

  replace("XabXcdXef", "X",    "|",                    4:=2,  1    );
is allowed in the moment.
It is allowed but I would not recommend it since it is difficult to process for the brain what will happen. In the above case , the last "1" will actually overwrite the previous "4:=2", since both refer to the argument at position 4 but the last definition wins.
PeterH wrote:But I think your idea isn't bad, i.e. a positional operand following a numbered operand should mean the operand with the previous number plus 1.
This is definitely not supported at the moment.
So I think the current way isn't helpful.
Result: my wish to change it.
(I don't expect someone to use the current solution.)

admin
Site Admin
Posts: 66730
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: scripting: numbered arguments QA

Post by admin »

Well I used it (and did not have any problems):

Code: Select all

popupmenu(":copypath|:dp|:pp", 5:=2);
Cannot fulfill your wish since it would break old code.

admin
Site Admin
Posts: 66730
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: scripting: numbered arguments QA

Post by admin »

Code: Select all

popupmenu(":copypath|:dp|:pp", 5:=2);
BTW, hijacking this thread, is this new flag "2" really necessary? I'm a bit sad that the cool new popupmenu functionality is only accessible via that weird flag. I mean, how big is the chance that somebody used scripted menu captions beginning with ; or : in the past, and even if, how big is the chance that anything dangerous happens now...

So, shouldn't this work without the flag:

Code: Select all

popupmenu(":copypath|:dp|:pp");

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: scripting: numbered arguments QA

Post by PeterH »

admin wrote:Well I used it (and did not have any problems):

Code: Select all

popupmenu(":copypath|:dp|:pp", 5:=2);
Cannot fulfill your wish since it would break old code.
I don't understand!

Do you expect that someone used

Code: Select all

  replace("XabXcdXef", "X",    "|",                    4:=2,  1    );
to *overwrite* operand 4 with 1 :?:


To your question to popupmenu(): I'd not expect problems, too.

But everybody expecting errors in these situation: please give info :!:

admin
Site Admin
Posts: 66730
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: scripting: numbered arguments QA

Post by admin »

PeterH wrote: Do you expect that someone used

Code: Select all

  replace("XabXcdXef", "X",    "|",                    4:=2,  1    );
to *overwrite* operand 4 with 1 :?:
No, but this (fictitious) example is a little more likely:

Code: Select all

  replace("XabXcdXef", "X",    "|",                    5:=2,  1    );

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: scripting: numbered arguments QA

Post by PeterH »

Do I understand something wrong?
In your last example you set the 5th operand to 2, then overwrite it by 1?
It seems you want to say something else. But whatever: is that documented, so that somebody "has a right" (and a reason) to use it?
So at least we need docu of how a pos operand following a numbered op is handled.

(By the way: just saw that the 1st op is 0. As a former programmer I don't understand this. As I would program for the users, not for a programming langue. As I wrote loooong ago, maybe for substr() or alike: I understand this for offsets, but not for numbering.)

admin
Site Admin
Posts: 66730
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: scripting: numbered arguments QA

Post by admin »

No, the "1" is the position 4 argument (positions start with 0).

No need for extra doc: it's either position or numbered, and the last for each position wins.

Post Reply