To array definitions

Features wanted...
Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: To array definitions

Post 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?

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

Re: To array definitions

Post by admin »

- no limits
- all expressions should work
- I don't see any mystery with $a. :?

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: To array definitions

Post 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?

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

Re: To array definitions

Post 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. :)

eil
Posts: 1617
Joined: 13 Jan 2011 19:44

Re: To array definitions

Post 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.
Win 7 SP1 x64 100% 1366x768

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: To array definitions

Post by Filehero »

admin wrote: 17 Aug 2022 23:13 Just don't use it if it makes you nervous. :)
:biggrin:

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: To array definitions

Post 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)...
One of my scripts helped you out? Please donate via Paypal

Post Reply