Page 1 of 3

To array definitions

Posted: 15 Aug 2022 20:05
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:

Re: To array definitions

Posted: 16 Aug 2022 09:34
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.

Re: To array definitions

Posted: 16 Aug 2022 10:00
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...

Re: To array definitions

Posted: 16 Aug 2022 10:29
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; 

Re: To array definitions

Posted: 16 Aug 2022 11:35
by PeterH
Reading it this way it looks much much better! :beer:

Re: To array definitions

Posted: 16 Aug 2022 13:19
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?

Re: To array definitions

Posted: 16 Aug 2022 13:29
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.

Re: To array definitions

Posted: 16 Aug 2022 14:04
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.

Re: To array definitions

Posted: 16 Aug 2022 14:19
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.

Re: To array definitions

Posted: 16 Aug 2022 15:19
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.

Re: To array definitions

Posted: 16 Aug 2022 15:24
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...

Re: To array definitions

Posted: 16 Aug 2022 15:36
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.

Re: To array definitions

Posted: 16 Aug 2022 17:40
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").

Re: To array definitions

Posted: 16 Aug 2022 17:53
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)

Re: To array definitions

Posted: 16 Aug 2022 18:17
by Filehero
:tup: :tup: :tup:

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