Documentation of "set $x, [reprocess]"

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Post Reply
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Documentation of "set $x, [reprocess]"

Post by PeterH »

The description of the set command, as well as the description of it's reprocess-operand seem to say that the last operand is "reprocess". Only some lines below under The reprocess argument it is mentioned, that it's only "r"!
I'd think it would be better to also allow "reprocess", (sure: don't delete "r",) and to mention both names in the operand description reprocess:

For the form $x = $y, "r";, info follows only inside the description of the set command. But I think people will look in: Advanced Topics / Scripting / Variables / Using the equal operator (=) - so I think there should be a note for reprocess, too. Sure it may refer to Scripting Commands / set.

-----

Edit - to the following wish: seems my expectations on eval() were too high: maybe it's exactly what I should use here?
Thought eval() would execute complete instructions, but it doesn't do that...


As being related to this, a wish: reprocess works on <...> and %...% variables. I think it could be very useful if it would also work on the normal $... variables! I think if a $...-name is used inside the text of a reprocessed string, it will be meant to be reprocessed.
(I just assumed this - and had to find out that it's not done...)
I know eval() could be used here - but as my request refers just to the values for variable names, not to the complete expression, I think it would be easier. And as other variables are resolved here...

My idea:

Code: Select all

   $script = "name";
   $pre = '$list<crlf><date hh:nn:ss> $script:';  // once define a line-prefix
   $list = ""; // init list to empty
// ... and then several times with varying text inside the script:
   $list = "$pre An added line.", "r";  // add a line to the list
// ... instead of
   $list = "$list<crlf><date hh:nn:ss> $script: An added line.";  // add a line to the list
(OK: if we had subroutines...)

You also could refer to array elements:

Code: Select all

 $x = 3;
 $y = 5;
 $i = '$i'.$x."_".$y, "r";  // $i = $i3_5;
(But to set an element eval() can't be avoided.)

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

Re: Documentation of "set $x, [reprocess]"

Post by admin »

reprocess: done
eval: no time

thanks :)

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

Re: Documentation of "set $x, [reprocess]"

Post by PeterH »

1) documentation in "set" seems to be fine now.
2) documentation in "Advanced Topics / Scripting / Variables / Using the equal operator (=)" should tell:
For the additional "reprocess" operand see description of the "set"-command.
3) testing showed: eval() is more flexible than "reprocess" *and* also substitutes script-variables like $x - very fine.
4) But IMHO a bug: eval() strips leading and trailing blanks! (At least it's not expected!)

Code: Select all

   $x = "|";
   $v = '   $x <date hh> <date nn> <date ss> <date hh:nn:ss> <date hh:nn:ss>:   ';
   $s = $x.eval($v)."more text!";
   text $s;
:arrow: the leading and trailing blanks of eval($v) are missing.

5) Above code, with the many <date ...> vars, is just a silly sample to show that all not-leading or not-trailing blanks keep intact. But it shows a bug that every second <date ...> isn't replaced. (I added even some more dates to show that better...) Note: tests show that there seem to be further factors.

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

Re: Documentation of "set $x, [reprocess]"

Post by admin »

4) Not a bug: You should add additional quotes to avoid the trimming:

Code: Select all

//
   $x = "|";
   $v = '"   $x <date hh> <date nn> <date ss> <date hh:nn:ss> <date hh:nn:ss>:   "';
   $s = $x.eval($v)."more text!";
   text $s;
5) Bug indeed! :shock: Incredible that this one wasn't caught earlier! Thanks!

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

Re: Documentation of "set $x, [reprocess]"

Post by PeterH »

admin wrote:4) Not a bug: You should add additional quotes to avoid the trimming:

Code: Select all

//
   $x = "|";
   $v = '"   $x <date hh> <date nn> <date ss> <date hh:nn:ss> <date hh:nn:ss>:   "';
   $s = $x.eval($v)."more text!";
   text $s;
5) Bug indeed! :shock: Incredible that this one wasn't caught earlier! Thanks!
5) I think it's not often used in this strange form? And as I said it dependents from something else - maybe the length of or the number of characters between the <date ...> expressions? But OK, if you found it!

4) Now for quite some time I didn't understand this - neither the logic nor the sense :oops:
Reason seem to be the documentation and the examples for eval(), together with some wrong expectations by me. Especially as I was on a usage offside from that shown by the examples...
(In the end I expected just the variables in the string to be evaluated, i.e. to be replaced by their contents.)

In real the operand of eval() is treated like the right side of an equation! And has to follow all rules for that! Especially constant parts have to be specified quoted, and have to be concatenated by dots! Sure: variables in double quoted strings will be resolved...

So in my example the string was wrong: it in principle had to be in double quotes - not only for the leading and trailing blanks, but also for the other blanks and the ":" being constant text!
If I want to achieve:

Code: Select all

   $s = "   $x  <date hh:nn:ss>:   ";
... I must specify for example:

Code: Select all

   $v = '"   $x  <date hh:nn:ss>:   "';
   $s = eval($v);
Before the result wasn't completely wrong, as XY is quite tolerant to such bad formed statements!

Don't get me wrong: my problem is only a lack in description of eval(), the function is very good this way! As it also allows constructs like:

Code: Select all

   $v = '"   $x ". substr($a,$i) ." <date hh:nn:ss>:   "';
   $s = eval($v); // will also evaluate the substr(), and concatenate it with the rest!
So it might help, if documentation of eval() would also show an example of such a more complex string with quotes, a function, and concatenation? And maybe mention "like the right side of an equation" somewhere? This will make use of quoting for eval() a lot more transparent, I think. (And gives hints for expanded usage...)

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

Re: Documentation of "set $x, [reprocess]"

Post by admin »

PeterH wrote:So it might help, if documentation of eval() would also show an example of such a more complex string with quotes, a function, and concatenation? And maybe mention "like the right side of an equation" somewhere? This will make use of quoting for eval() a lot more transparent, I think. (And gives hints for expanded usage...)
Yes, I added something to the help.

Post Reply