Page 1 of 2
scripting: numbered arguments QA
Posted: 15 Jun 2017 21:41
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.
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 00:35
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...)
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 06:30
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
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 09:35
by admin
Searching the change log for ":=" would have taken you 10 seconds to find this.
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.
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 10:28
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);
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 10:37
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.
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
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?
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 11:23
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!

Fix coming...
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 12:19
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.
Re: Undocumented script commands - Suggestions
Posted: 16 Jun 2017 12:41
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.)
Re: scripting: numbered arguments QA
Posted: 16 Jun 2017 12:59
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.
Re: scripting: numbered arguments QA
Posted: 16 Jun 2017 13:04
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:
Re: scripting: numbered arguments QA
Posted: 16 Jun 2017 13:14
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

Re: scripting: numbered arguments QA
Posted: 16 Jun 2017 13:57
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 );
Re: scripting: numbered arguments QA
Posted: 16 Jun 2017 14:51
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.)
Re: scripting: numbered arguments QA
Posted: 16 Jun 2017 15:14
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.