Page 3 of 3

Re: To array definitions

Posted: 17 Aug 2022 19:41
by Filehero
@Don

What will be the restrictions/limits for
- key strings (e.g. length, allowed chars, variable interpolation etc.)
- index expressions (e. g. will boolean expressions resolving to 0|1 be also valid, or just simple two operands math with *, +, -)
?



The root variable is still puzzling to me.

v23.50.0015 - 2022-08-15 16:56: $a is a "normal" variable

Code: Select all

  - Array variables and normal variables with the same base name can be used side by 
    side like different variables:
     $a ="cat"; $a[0] = "dog"; echo $a; echo $a[0]; //"cat", "dog"

v23.50.0016 - 2022-08-16 13:09: and here it's the "root" one, though the code is equivalent.

Code: Select all

    $a = "I am Groot!"; //root variable
    $a[0] = "Hi!";
How does the parser know the difference - and what is the difference under the hood?

Re: To array definitions

Posted: 17 Aug 2022 21:11
by admin
- no limits
- all expressions should work
- I don't see any mystery with $a. :?

Re: To array definitions

Posted: 17 Aug 2022 21:46
by Filehero
admin wrote: 17 Aug 2022 21:11 - all expressions should work
What terminates such "expressions"?
Can I theoretically use a multi-line script with three ";"-/line-feed-terminated commands followed by a function with an integer return value?
Or is the rule rather generic like "the first return value" wins and will be consumed by the parser (and nevertheless will cause a runtime error if the return value is an invalid value for the array index)?

admin wrote: 17 Aug 2022 21:11 - I don't see any mystery with $a. :?
So, conceptional the "root" variable simply is a "normal" variable? Or the other way round, every variable becomes a "root" one once I "index/key assign" a value using its existing identifier literal?

Re: To array definitions

Posted: 17 Aug 2022 23:13
by admin
An "expression" is not a script, and is not a script line ending with ";". An "expression" is a term that resolves in one single string or number.

Don't worry about the root. Just don't use it if it makes you nervous. :)

Re: To array definitions

Posted: 18 Aug 2022 09:17
by eil
klownboy wrote: 17 Aug 2022 01:07 The "Say Hi", "Say Bye", and "_Terminate" are separate scripts in this case. Each script is not indented. If you comment out those 3 global $a[]; statements, you'll see it doesn't work.
Hope i got it right: only one of these will be run and no sub-script calling, so processing ends, Globals being erased.(proving that a new-scripters should not use Globals and use more understandable Perms)

@LittleBig thanks for pointing the proper name.

Re: To array definitions

Posted: 18 Aug 2022 09:27
by Filehero
admin wrote: 17 Aug 2022 23:13 Just don't use it if it makes you nervous. :)
:biggrin:

Re: To array definitions

Posted: 18 Aug 2022 10:08
by highend
proving that a new-scripters should not use Globals and use more understandable Perms
It depends on what you are doing...

E.g.:

Code: Select all

- Sharing variables between scripts in a multiline-script (with initialize / terminate sections): Better use a perm instead of redefining the same globals all over again
  It gets messy with many subscripts and more error prone (oops, I did forget to define in one subscript and it doesn't behave like it should) instead of init + unset the perm
- Transferring variables over to completely different scripts (different files): Perm is the only way (apart from storing them in files)
- Even for user-written functions (if you have multiple), I'd prefer perm (don't forget to unset it at the end of the script)...