Hello,
I'm glad you felt the need to add a function to fill an array in 1.99.99.56 - [r848].
This was the problem of most older programs.
(below are some of my old notes)
My proposal is to use instead of a new function this method:
fill array_name with value array_name = "" array_name = 0 or array_name[] = "" array_name[] = 0
Now we got:
1) Declare an empty array: dim array_name(2,3) dim array_name[2,3] 2) Declare and assign an array by using a list of elements (one by one element) array_name = {1,2,3,4,5,6} array_name = {{1,2,3},{4,5,6}} array_name[] = {1,2,3,4,5,6} array_name[] = {{1,2,3},{4,5,6}}
It will be nice to have also:
3) Fill an array (assign one element to entire array) array_name = "" array_name = 0 array_name[] = "" array_name[] = 0 4) Assigning an array from another array array_name = {1,2,3,4,5,6} new_array = array_name #redim and fill from source
So, ( array[]
and array
are the same thing)
array[] = int #fill array with int array[] = float #fill array with float array[] = string #fill array with string array[] = array[] #redim array and fill from second array array[] = {list} #redim array and fill from list
or in conjunction with dim or redim:
dim array(x) = int #dim/redim fill array with int dim array(x) = float #dim/redim fill array with float dim array(x) = string #dim/redim fill array with string dim array(x) = array[] #dim/redim redim array and fill from second array dim array(x) = {list} #dim/redim array and fill from list
Eg.
dim a(10) a="" #or a[]="" to fill array with "" dim b(20) b[]=0 #or b="" to fill array with 0 a=b #clear a array, redim a(20) and copy content of b into a #is the same as dim a=b dim c(2,3)="" #complex: create an array and fill it dim z(5,8)=0.1 z=c #clear z array content and make a copy of c array c=x #if x is int/float/string create an array and fill it #if x is array then clear c array content and make a copy of x array #ERRORS dim c(2,3)={1,2,3} #error: declared dimensions do not match those provided dim x(10,10) dim c(2,3)=x #error: declared dimensions do not match those provided dim c=x
Not a bad move addition of fill function, but I think that filling an array coud be done more intuitively.
I also believe you should avoid adding new functions when possible. Their removal future will create more compatibility issues.
Its up to you.
PS Anyway, you did a great job with the latest upgrades. The code is more logical and you have eliminated a lot of dummy DataElement creation on errors. And the code is much, much faster!
Great... great job!
in 1.99.99.57
I totally agree that it would have been nice to use the "=" sign to fill an array but the parser does not know if a variable is an array name or if we should use the value in the variable.
Now we got:
I would like to get rid of the empty bracket notation [] but...
This might not be exactly what you were thinking, but it will work well and was easy to make the lexer and interperter handle.
I took some time of thinking and I came to the following conclusions.
(I will use only C-like notation: array[])
You say:
var1 (of any kind would have been) will become a copy of var2. Simple and clear.
1) Declare DIMensions of an empty array and optionally fill with a single value:
2) Assign an array by using a list of elements and dimensioned array on the fly according to the list provided:
I have doubts that those two lines below should be accepted in conjunction with DIM command. DIM means declaring DIMensions and we declare none:
This is just an assignment
A true DIM command should be like this:
but this could generate others errors (dimensions != list elements). Eg.:
3) Fill an existing array (assign one element to entire array)
But I don't think those lines below should work
DIM means "declare DIMensions for the array" So, If we translate this command
it will sound like this:
I declare DIMensions for the array... with unknow size and fill it with ""
4) Assigning an array from another array
See point 2
This is a pure assign operation. This should be just: var1=var2
Results:
+just an opinion
Instead of FILL would not look better <<?
Speaking of square brackets, the idea is to give the user the ability to use C style when it comes to arrays.
Standard style:
C style:
I added just a single line (554) for that in basicParse.y file to work.
Back to arrays...
I'm not sure of anything right now.
I feel like there must be something simple.
But I needed to say what conclusions I reached.
I attach basicParse.y file.
Solve only syntax like above and not the actual code.
It is just an opinion.
Respectfully,
Florin Oprea
1.99.99.67 added 2d array access by a[][] and length access by a[?][] and a[][?]