Author |
Message |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Thu Sep 13, 2007 6:42 am Post subject:
Array dismay |
|
|
I have an array of data which I can look up each element individually and return a value for each element.
Code: |
float Data;
float Array[][];
[
[1.0,2.0,3.0,4.0],
[1.1,2.1,3.1,4.1]
] @=> Array;
Array[0][2] => Data;
<<<Data>>>; // Should print 3.0
1::second => now;
|
This is all well and good but.....
If I want to have an element that stores two numbers, how do I go about making the variable "Data" equal to both the stored numbers?
Is this possible or would I have to have two seperate variables, one to store the first number and one to store the second number for that element?
I.e.
Code: |
float Data;
float Array[][];
[
[1.0,2.0,(3.0,3.2),4.0], // (3.0,3.2) meaning 3.0 && 3.2
[1.1,2.1,3.1,4.1]
] @=> Array;
Array[0][2] => Data;
<<<Data>>>; // Should print 3.0 and 3.2
1::second => now;
|
If this isnt feasible how could I tell ChucK to pass the second number for that element into another variable should it exist which wouldnt always be the case and would that cause further problems if it were the case?
Many thanks
Rhys |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Sep 13, 2007 7:40 am Post subject:
|
|
|
Ok. This, I fear, is not going to work.
If something is a "float" it will hold one floating point number, no more, no less, nothing else. So; if something is a array of floats it will be a array of just single numbers, not say, a list of floats.
What you are after seems to be some sort of new thing. That's no problem, we can define our own as a class or, if two numbers max will do, we could abuse the new complex numbers (see the docs for the latest release).
How this would work will depend mostly on how you are planning to get the numbers into the delay and where they will go afterwards.
You could also make a array like this;
float array[3][n];
where array[0][n] would hold the first float, array[1][n] would hold a zero or a one, depending on whether a second float is needed and array[2][n] would hold the second float if it's used.
You'd then write the functions that deal with it all around that format.
It really depends on what you'd like to do and how. _________________ Kassen |
|
Back to top
|
|
|
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Thu Sep 13, 2007 7:53 am Post subject:
|
|
|
So are you saying it is not possible to have something along the lines of....
Code: |
float Data;
float Array[][]; // would this need to be changed to accomodate an array for an element?
[
[1.0,2.0,[3.0,4.0],4.0], // An array within an array?
[1.1,2.1,3.1,4.1]
] @=> Array;
Array[0][3] => Data;
<<<Data>>>; // Should print 3.0 and 3.2
1::second => now;
|
This code doesnt work but shows what I'm aiming for.... |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Sep 13, 2007 9:56 am Post subject:
|
|
|
Yes, I understand what you want but that won't work.
If you define a array as being type "float" all entries will have to be of type "float" and you can't have entries that are a list of floats or a array of floats or whatever.
I'm very sorry but ChucK is "strongly typed" so that means if you say there is going to be a float there will have to be a float (also; you need to say what it's going to be) (also; there can't be anything else in addition to the float).
You can have a array of arrays of floats but then those all need to be the same length.
So, that's no, no, absolutely not. :¬)
Why not? I hear you ask... For one thing this way you always know for sure what you are going to get, and so does ChucK. I'm sure there are many other more more profound reasons, for these you will need somebody like Ge or Spencer who have studied this stuff. I never implemented a programming language, you see....
What you can do is have a array of identical length arrays and not use some of the locations, provided you come up with a clever way of telling chucK which ones are in use (see above for a example). _________________ Kassen |
|
Back to top
|
|
|
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Thu Sep 13, 2007 10:02 am Post subject:
|
|
|
hmm...
I'll see if it can be implemented another way such as you suggested before. I can understand why it is not easily done but it is frustrating none the less.
Thanks again
Rhys |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Sep 13, 2007 10:34 am Post subject:
|
|
|
I understand.
How about taking a step back, looking at the problem you are trying to solve or instrument you are trying to build and seeing whether you can abstract the data in some different way that would fit better? That could perhaps get you 'round this frustration. _________________ Kassen |
|
Back to top
|
|
|
|