To array definitions

Features wanted...
PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

To array definitions

Post by PeterH »

This is like "my expectation" of things - so in "Wishes".

If I interpret your definition of "global arrays" correct, it's the wrong name. :P As it seems you don't define the array as global, but distict array elements. :shock:
For me this looks *very* strange. Results in an array where parts are global and others are not - to me this almost seems like two different arrays.

I'd generally expect that an array as a whole is to be defined global. Like "global array[];"
If you won't: please allow something like "global array[*];" :ugeek:
W7(x64) SP1 German
( +WXP SP3 )

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

Re: To array definitions

Post by eil »

+1 While i was reading changelog, i totally missed the right logic at examples with numerous stating that separate array elements are global, and most of when array element was stated as global for second time though it was already before.
There should be a need of one time stating array being global, and any mention later in any section of same script file should treat it as global. No perm is not a big deal, each array can be saved by user individually in mere txt file.
Win 7 SP1 x64 100% 1366x768

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 »

PeterH wrote: 15 Aug 2022 20:05 This is like "my expectation" of things - so in "Wishes".
Totally right, of course. Let me try again...

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 »

Next beta:

Code: Select all

"_Initialize"
  global $a[];
  $a = "I am Groot!"; //root variable
  $a[0] = "Hi!";
  $a[1] = "Bye!";
"Say Hi"
  global $a[];
  echo $a[0];
"Say Bye"
  global $a[];
  echo $a[1];
"_Terminate"
  global $a[];
  echo $a; 

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Re: To array definitions

Post by PeterH »

Reading it this way it looks much much better! :beer:
W7(x64) SP1 German
( +WXP SP3 )

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

Re: To array definitions

Post by Filehero »

PeterH wrote: 16 Aug 2022 11:35 Reading it this way it looks much much better! :beer:
Yes, :tup:

But to be honest, I didn't get the "root variable" thing yet. Is that an additional slot in the array?

LittleBiG
Posts: 1846
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: To array definitions

Post by LittleBiG »

Filehero wrote: 16 Aug 2022 13:19
PeterH wrote: 16 Aug 2022 11:35 Reading it this way it looks much much better! :beer:
Yes, :tup:

But to be honest, I didn't get the "root variable" thing yet. Is that an additional slot in the array?
I have never heard about that either. I mean, from array point of view. Actually it might be good for storing some description of the whole array.

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Re: To array definitions

Post by PeterH »

Another thing. (I react early, before it's too late...)

You write, for example:
You can only pass literal strings as values, not variables.
Sounds very strange! XY till now defines rather good, what Text, number, or variable is. For me: values (and indexes) should depend on the same definitions. So I'd expect:
- an index to be 7 or a variable containing the same
- an index to be 'name' or "name" (with dflt rules like anywhere) or a var
- the same for values. Be it initialization or normal setting.

This way nobody has to learn (and differentiate) other syntax.

I hope you understand what I want to say.
W7(x64) SP1 German
( +WXP SP3 )

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 »

1) root variable: In other languages you get an error when you use an array variable without index. But XY can tolerate it the way it is built here. Think of it as an additional element.

2) You can only pass literal strings as values, not variables. AFAIK it is like that in PHP. But I'm not sure.

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Re: To array definitions

Post by PeterH »

admin wrote: 16 Aug 2022 14:19 2) You can only pass literal strings as values, not variables. AFAIK it is like that in PHP. But I'm not sure.
If this is for something like initialization (say in array()) I think it *might* be tolerated.

But if

Code: Select all

a[1] = $var;
 a[$nr+3] = $other * 4;
wouldn't be ok - I think I wouldn't need arrays :evil:

In other words: the index [...] and the value should just :roll: be normal expressions as elsewhere, and all is fine.

For me an array is nothing but a group / list of variables, belonging together, and often being worked on by index or key.
W7(x64) SP1 German
( +WXP SP3 )

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

Re: To array definitions

Post by highend »

Yeah, I guess expressions are mandatory.

For example if you want to create an associative array by parsing a structured text file (e.g. a .ini). Not possible without expressions / variables...
One of my scripts helped you out? Please donate via Paypal

LittleBiG
Posts: 1846
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: To array definitions

Post by LittleBiG »

PeterH wrote: 16 Aug 2022 15:19
admin wrote: 16 Aug 2022 14:19 2) You can only pass literal strings as values, not variables. AFAIK it is like that in PHP. But I'm not sure.
If this is for something like initialization (say in array()) I think it *might* be tolerated.

But if

Code: Select all

a[1] = $var;
 a[$nr+3] = $other * 4;
wouldn't be ok - I think I wouldn't need arrays :evil:

In other words: the index [...] and the value should just :roll: be normal expressions as elsewhere, and all is fine.

For me an array is nothing but a group / list of variables, belonging together, and often being worked on by index or key.
Actually I also misunderstood it first. This "literal" stuff is only for the array() command. If you want to fill up the array by that command, you have to know the values in advance. Otherwise you can use variables.

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

Re: To array definitions

Post by Filehero »

highend wrote: 16 Aug 2022 15:24 Yeah, I guess expressions are mandatory.
And nested arrays (with a nesting depth/dimension limit, if it is required) for (simple) tree-related "structures" (e.g., "value objects").

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 »

Coming... :) :cup: :cup: :cup:

Welcome to the happy world of nested arrays:

Code: Select all

$b[0] = "pus"; $b[1] = "sy"; $a[$b[0] . $b[1]] = "cat"; echo $a[$b[0] . $b[1]]; //cat
(preview of next beta)

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

Re: To array definitions

Post by Filehero »

:tup: :tup: :tup:

@me: should I rewrite some parts of my existing script lib?

Post Reply