Help file - small improvements...

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".
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Help file - small improvements...

Post by PeterH »

Borut wrote:I was not able to find the relevant description in the on-line help (if there already is one about "", then it should perhaps be made more visible (what Don is going to do)),
As I was sure I had seen it before I now just had a look...

In Scripting Commands Reference, under description of the global command, you read:

Code: Select all

variable(s)
   A single variable, or a comma-separated list of up to 10 variables. If a
   variable has already been defined as global before, then the global
   command initializes it to its current global value, else it is initialized to an
   empty string. 
But OK: if this isn't described in the description of global variables, it should be added there, too.

And note: here Don talks about the definition of a global variable.
If it's not (yet) defined as global, it's not global, it's undefined, and it's not initialized.
If it is defined global, it's global, it's defined, and it may be initialized or not.
So, for a global variable, it can be defined but uninitialized. But you can not use it undefined - as then it's not a global.

A non-global variable, if necessary, is implicitly defined by assigning it a value. But if you reference it without assigning a value before, you reference a non-defined variable! Something that never can happen with a global variable.
Now reference of a non-defined variable shows the name of the variable, while reference of a defined but uninitialized variable shows "".
If you could define a normal variable without assigning it a value, it should show "", too.

So there is some logic with the way it works...

And as last to my code-snippet: If you assign the name of a variable to that variable, you don't "un-define" it, or empty it! It looks the same as if it would be not defined - but it's filled with a string of characters! For this you might read the definition of the unset command. The same is for setting a (global) variable to "".

I remember another scripting language having a function defined() (or so) to test for the definition-status of a variable - you supply a variable name, and it returns something like undefined / variable / global. (You still have a problem with a global containing "": is it un-initialized, or is it set to empty?)

Borut
Posts: 1472
Joined: 19 Oct 2010 19:29
Location: Win10 Pro 64b 22H2, @120DPI (125%)

Re: Help file - small improvements...

Post by Borut »

Thank you for these clarifications Peter.
Win 10 Pro 64bit

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

Re: Help file - small improvements...

Post by admin »

Borut wrote:... I have learned the hard way that the one about regular variables does not apply to perm variables.
I still don't understand where regular variables differ here from perm variables. Please give code example.

I think this code proves that all three variable types are treated the same (initialized to empty string):

Code: Select all

"variables initial states"
  releaseglobals;
  perm $a_perm;
  global $a_glob;
  set $a_loc;
  msg "|$a_perm|$a_glob|$a_loc|";

Borut
Posts: 1472
Joined: 19 Oct 2010 19:29
Location: Win10 Pro 64b 22H2, @120DPI (125%)

Re: Help file - small improvements...

Post by Borut »

Don, yes. My error/omission was not to know/expect/find that perm and global are making an implicit set to "" (hope that I got this correct now). Therefore, for your last example, I would previously expect (until you have explained this a few days ago) that $a_perm and $a_glob would not be initialized and therefore resolve to '$a_perm' and '$a_glob' respectively, but not to "".
Win 10 Pro 64bit

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

Re: Help file - small improvements...

Post by admin »

Borut wrote:Don, yes. My error/omission was not to know/expect/find that perm and global are making an implicit set to "" (hope that I got this correct now). Therefore, for your last example, I would previously expect (until you have explained this a few days ago) that $a_perm and $a_glob would not be initialized and therefore resolve to '$a_perm' and '$a_glob' respectively, but not to "".
Yes, I understand. But the XY scripting engine will resolve a variable once it "knows" about it, and until any other value is set the initial value is "".

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

Re: Help file - small improvements...

Post by PeterH »

As far as I understand I think XY's handling is OK.

But maybe there should be a bit more info in the documentation for this?

Script-command "global" describes it very good.
But in Scripting/Variables you only find:
Variables that are not set to any value are not resolved, but displayed:
msg $a; // Displays "$a" if $a has not been set to any value before.


I think this doesn't account for globals and permanent variables! So here should be a hint that for global and permanent variables the (name it?) "default value" (or "uninitialized value" or whatever) is ""? For me this is the most important place to mention, and should help users quite a lot. (Probably Borut has looked here, too.)

And at last in description for command "perm" - though it's less important here, and doesn't fit very well.
(Who uses perm should know about global, which often enough is referred to in perm...)

Borut
Posts: 1472
Joined: 19 Oct 2010 19:29
Location: Win10 Pro 64b 22H2, @120DPI (125%)

Re: Help file - small improvements...

Post by Borut »

PeterH wrote:But in Scripting/Variables you only find:
Variables that are not set to any value are not resolved, but displayed:
msg $a; // Displays "$a" if $a has not been set to any value before.


I think this doesn't account for globals and permanent variables! So here should be a hint that for global and permanent variables the (name it?) "default value" (or "uninitialized value" or whatever) is ""? For me this is the most important place to mention, and should help users quite a lot. (Probably Borut has looked here, too.)
Thank you Peter! Yup, that was the fatal place and - for a quite some time - I did not look any further. :cry:
Win 10 Pro 64bit

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

Re: Help file - small improvements...

Post by admin »

OK, I changed that part in Help:
Variables (or better: strings that look like variables) that have not been explicitly (by set, global, or perm) or implicitly (by setting them to any value) declared as a variable, are not resolved but displayed as they are:
msg $a; // Displays "$a" if $a has not been declared or set to any value before.

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

Re: Help file - small improvements...

Post by PeterH »

admin wrote:OK, I changed that part in Help:
Variables (or better: strings that look like variables) that have not been explicitly (by set, global, or perm) or implicitly (by setting them to any value) declared as a variable, are not resolved but displayed as they are:
msg $a; // Displays "$a" if $a has not been declared or set to any value before.
Sorry - I don't think that's easy to understand...
(...easy to say, I know :roll: )

I think I'd say it from another point of view, like:

Local variables, until they are set the first time, return their name as value.
Global and permanent variables, when defined global or perm, but never have been set to a value, return "".

Code: Select all

   msg $a; // Displays "$a" if $a has not been set to any value before.
   global $b;
   msg $b; // Displays "" if $b has not been set to any value before.
I hope this says more direct what's to know?

Borut
Posts: 1472
Joined: 19 Oct 2010 19:29
Location: Win10 Pro 64b 22H2, @120DPI (125%)

Re: Help file - small improvements...

Post by Borut »

PeterH wrote:Local variables, until they are set the first time, return their name as value.
Global and permanent variables, when defined global or perm, but never have been set to a value, return "".

Code: Select all

   msg $a; // Displays "$a" if $a has not been set to any value before.
   global $b;
   msg $b; // Displays "" if $b has not been set to any value before.
Thank you once more Peter - you are speaking from my soul. Don, please, just take this what Peter has written and put it into help file :wink:
Win 10 Pro 64bit

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

Re: Help file - small improvements...

Post by admin »

Thanks, I'll improve it.

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

Re: Help file - small improvements...

Post by PeterH »

Maybe small inconsistencies? I just happened to see:

In help, for the command "status", in the last example:
status "Whoops!", "FF0000", alert
the icon-name alert is shown without quotes. Is that formally correct? (It works, but I think it's strange...)
And: all examples here miss the ";" at the end - that's not consistent with other commands.

Also examples for command assert lack use of ";"

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

Re: Help file - small improvements...

Post by admin »

Thanks!

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

Re: Help file - small improvements...

Post by PeterH »

Just had a look at get() in help.

A part of it is described as it should: for a function call. Example:
echo get("curitem",); //E:\Test\b\c\Jane.txt

But a lot of examples are described in the variable-form, i.e.:
echo <get alias Greet> //::echo "Hello, <@1>! It's <@2 Dewey>!";
text <get drives>; //A:\|C:\|D:\|E:\|F:\|H:\|T:\|X:\|Y:\|Z:\
text <get drives 0>; //
text <get drives 1>; //Z:\
text <get drives 2>; //A:\
text <get drives 3>; //C:\|D:\|E:\|F:\|T:\
text <get drives 4>; //X:\|Y:\
text <get drives 5>; //H:\
text <get drives 6>; //

I think this is inconsistent, and confuses people searching for information.
(And the "echo <get alias Greet> //..." misses the ";".)

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

Re: Help file - small improvements...

Post by admin »

Thanks!

Post Reply