Load series of variables from Array or List

General support topics
Post Reply
User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Load series of variables from Array or List

Post by Dutchman » Fri Nov 01, 2019 6:37 pm

For a plot program under construction I am looking for a simple way to assign a series of variable values from an array.
In the example, a ... j is a series of 10 variables and Default is an array with the desired values:
DIM Default () = (0,1,2,3,4,5,6,7,8,9)
The simplest would be if the following command could be given:
a, b, c, d, e, f, g, h, i, j = Default
but unfortunately that doesn't work because of Type Mismatch.
That is why I now have the following solution:

Code: Select all

'Load data,'load a list of variables
'by Ton Nillesen, Novenber 2019
'
DIM Default()=(0,1,2,3,4,5,6,7,8,9)
a,b,c,d,e,f,g,h,i,j=Load10|10(Default)
PRINT "a =";a
PRINT "b =";b
PRINT "c =";c
PRINT "....."
PRINT "j =";j
END
'
DEF Load10(a())
' return 10 values from array
RETURN a(0) a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9)
END DEF
The disadvantage is that a different function must be created for each length of the series of variables.
No problem, but not elegant
Last edited by Dutchman on Fri Nov 01, 2019 10:42 pm, edited 1 time in total.
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: Load series of variables from Array

Post by kibernetik » Fri Nov 01, 2019 6:50 pm

Ok, but it will be useful to know the source of the problem:

1. There is an elegant way to do this in another language and you are missing it in BestBASIC?
2. a,b,c,d,... = 0,1,2,3,4,... assignment does not suit?
3. READ/DATA operation does not suit?
4. This feature does not exist in any language, but you think that it should exist in BestBASIC?

Some comments:
a) The string
a, b, c, d, e, f, g, h, i, j = Default
gives a type mismatch error because it will be correct if a,b,c,d,... are arrays:

Code: Select all

dim a(),b(),c(),d()=0,1,2,3,4,5
a,b,c = d
b) Any user function can return any number of values:

Code: Select all

def f x,n
if n=1 then return x(0)
if n=2 then return x(0) x(1)
if n=3 then return x(0) x(1) x(2)
end def

dim m()=0,1,2,3,4,5

a = f(m,1)
a,b = f|2(m,2)
a,b,c = f|3(m,3)
c) The READ/DATA operation works even for non-static values:

Code: Select all

dim m(4)=0,1,2,3,4

read a,b,c,d,e
print a; b; c; d; e

data m(0) m(1) m(2) m(3) m(4)

User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Load series of variables from Array

Post by Dutchman » Fri Nov 01, 2019 9:00 pm

kibernetik wrote:
Fri Nov 01, 2019 6:50 pm
1. There is an elegant way to do this in another language and you are missing it in BestBASIC?
2. a,b,c,d,... = 0,1,2,3,4,... assignment does not suit?
3. READ/DATA operation does not suit?
4. This feature does not exist in any language, but you think that it should exist in BestBASIC?
I am developing a plot program that automatically generates the basic elements for making a graph.
It starts with setting up the "canvas". as shown in the following figure:
.
Initial set-up.JPG
Initial set-up.JPG (71.57 KiB) Viewed 209 times
.
For this set-up alone, 15 variables must be transferred from either a list or DATA series of either default settings or user input.

ad 1, I don't know an elegant solution in another language and I have a solution that can be used for my problem.
ad 2, No, they are variable
ad 3, That is additional processing. Now I use: DIM Canvas()=(.....} or Canvas=Default or Canvas=UserData
ad4, that is up to you

I had hoped that you would know or propose an elegant method. So I will continue with my own solution.
It is no problem to create multiple LoadN() functions for solving a local problem in the library under development.
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: Load series of variables from Array

Post by kibernetik » Fri Nov 01, 2019 9:15 pm

Dutchman wrote:
Fri Nov 01, 2019 9:00 pm
I had hoped that you would know or propose an elegant method. So I will continue with my own solution.
It is no problem to create multiple LoadN() functions for solving a local problem in the library under development.
I still do not understand the problem you are facing with.
I understand that you have some array with values. I understand that you need to use variables instead of array values.
But I see no problems with it. Am I missing something?

I also cannot understand this phrase:
Dutchman wrote:
Fri Nov 01, 2019 9:00 pm
ad 2, No, they are variable
Do you mean "variable" is what is on the right side of assignment? Of course you can write:

Code: Select all

a,b,c = default(0) default(1) default(2)
or do you mean something else?

To apply a solution I should understand the problem which needs to be solved.

User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Load series of variables from Array or List

Post by Dutchman » Fri Nov 01, 2019 10:25 pm

For my DSDP library I want to show in graphs:
FFT, IFFT, FIRgain linear, FIRgain logarithmic, and Phase-response.
So I have at leat 10 sets of variables, 5 default and 5 user specific.
Per set the number of variables will be about 25, 15 for the "canvas" plus some for the axes etc.
So I decided to use lists for these sets.

For the transfer of these data to the actual required values I need a certain load function.
The use of a(x) etc. is unusable because it becomes unreadable.

I would like to have a function that transfers data from a list to a series of variables where the only requirement is that the number of elements in the list is at least as large as the number of variables.

I am now sufficiently satisfied with the solution that I have. The number of variables is not variable, so it is possible with one or two "LoadN(…)" functions, with N = 15 and 9 for example.

I now consider this topic closed. ;)
It is still a long way to go

Post Reply