can not understand the Array syntax
Date | 2016-12-12 09:25 |
From | Anton Kholomiov |
Subject | can not understand the Array syntax |
I can not get the assignment to arrays for operations that work on arrays as a whole. Do you need to preallocte the output array? Or it's going to be created after the operation is completed. kDest[] arrayOperation kSrc[] Do you have to write [] only for outputs but not for inputs? I saw the statements like this: kArr2[] = kArr1 + 10 Anton |
Date | 2016-12-12 14:29 |
From | Steven Yi |
Subject | Re: can not understand the Array syntax |
Hi Anton, Yes, the notation for arrays reflects an underlying change in Csound 6 with how variables are processed by the compiler. For arrays, the rule is that the first time they are assigned on the left-hand side of an opcode, they need to have [] to denote the type of the variable. For example: kArr2[] = karr1 + 10 kArr2 = karr2 + 2 would work. In Csound 6, the parser, when encountering a variable name for the first time, figures out its type and enters it into a table. It uses the [] to figure out the var is an array-type. Afterwards the variable name is used to lookup the type. This underlying change from previous Csound's was necessary foundation work for what is allowed in Csound 7: myvar:i = 1 myOtherVar:k = 4 kval = myOtherVal + myvar and matches expectations from other programming languages, like C: int myvar = 1; int myOtherVar = 4; myOtherVar = myvar + myOtherVar; where the types are only designated upon their first use. The explicit types above ties into user-defined datatypes and new UDO syntax in CS7: struct Rectangular x:i, y:i struct Polar R:i, t:i opcode to_polar(num:Rectangular):(Polar) ipolarR = sqrt(num.x ^ 2 + num.y ^ 2) ipolart = taninv2(num.y, num.x) * (360 / (2 * $M_PI)) retVal:Polar init ipolarR, ipolart xout retVal endop instr 1 r:Rectangular init 1.0, 0.5 polar:Polar = to_polar(r) print polar.R ; 1.118 print polar.t ; 26.565 endin Hope that didn't stray too far from talking about array notation, but I wanted to explain a bit of how that worked as I thought it might be helpful. steven On Mon, Dec 12, 2016 at 4:25 AM, Anton Kholomiov |
Date | 2016-12-12 14:35 |
From | Rory Walsh |
Subject | Re: can not understand the Array syntax |
Nice info there Steven. What's num for? I see you need to use it when passing struct to an opcode?
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
|
Date | 2016-12-12 14:40 |
From | Steven Yi |
Subject | Re: can not understand the Array syntax |
num here is the input argument to the to_polar opcode. The num:Rectangular uses the same explicit-type syntax for the opcode input arguments as used for explicitly defining variable types within code. This remind me that I essentially have this all documented within my PhD thesis, which might be a useful reference here. I'll post a link to that in a separate email. On Mon, Dec 12, 2016 at 9:35 AM, Rory Walsh |
Date | 2016-12-12 16:07 |
From | Oeyvind Brandtsegg |
Subject | Re: can not understand the Array syntax |
Wow, this is great. Looking forward to 7. Thanks for all the work on this, Steven (and Victor). 2016-12-12 6:40 GMT-08:00 Steven Yi |
Date | 2016-12-12 16:10 |
From | Anton Kholomiov |
Subject | Re: can not understand the Array syntax |
Thanks for explanation Steven, that makes things a bit more complicated for me as grammar becomes context dependent, but I hope I would figure out how to handle this case.. 2016-12-12 19:07 GMT+03:00 Oeyvind Brandtsegg <oyvind.brandtsegg@ntnu.no>: Wow, this is great. Looking forward to 7. Thanks for all the work on |
Date | 2016-12-12 16:12 |
From | Anton Kholomiov |
Subject | Re: can not understand the Array syntax |
But what if I write: kArr2[] = karr1 + 10 kArr2[] = karr2 + 2 How is it going to be interpreted by compiler? 2016-12-12 19:10 GMT+03:00 Anton Kholomiov <anton.kholomiov@gmail.com>:
|
Date | 2016-12-12 16:20 |
From | Peter Burgess |
Subject | Re: can not understand the Array syntax |
I'm clearly a bit behind here. Is Csound 7 about to be released then? I though t you'd just released 6.08. And what you guys are talking about here are changes coming up in Csound 7? On 12 Dec 2016 4:12 p.m., "Anton Kholomiov" <anton.kholomiov@gmail.com> wrote:
|
Date | 2016-12-12 16:34 |
From | Steven Yi |
Subject | Re: can not understand the Array syntax |
I did a quick test and it looks like that actually works alright. (I was expecting a compilation error myself.) I think that the parser code finds the "kArr2[]" and parses it as "kArr2" with metadata the var is an array. The metadata would be used on first-encounter with kArr2 and ignored if found again. However, this seems like a bug, as is demonstrable with the following code: |
Date | 2016-12-12 16:41 |
From | Anton Kholomiov |
Subject | Re: can not understand the Array syntax |
Ok! It works right now, but I shouldn't rely on this behavior. 2016-12-12 19:34 GMT+03:00 Steven Yi <stevenyi@gmail.com>: I did a quick test and it looks like that actually works alright. (I |
Date | 2016-12-12 17:11 |
From | Steven Yi |
Subject | Re: can not understand the Array syntax |
Hi Peter, Csound 7 is not about to be released, but there has been work ongoing towards it. We have been tracking things for Csound 7 here: https://github.com/csound/csound/milestone/12 Being a major version number change, CS7 has changes that are backwards incompatible for its API as internal things are changing (the Csound ORC and SCO language will be backwards compatible though). We were talking about maybe moving primary development towards CS7 at the Csound 30 conference, but the scheduling depends upon what comes up for issues. For CS7, I imagine once we shift to it, it will require some time to finish implementing new features and doing testing to ensure backwards compatibility for the langauge is preserved. Documentation will also take up time. The plan is that once we move to CS7, CS6 will remain in development within a separate branch of code, primarily for bug fixes and smaller features that do not require internal/API-breaking changes. Any features introduced in CS6 while CS7 progresses will of course be merged into CS7. Hope that clears that up! steven On Mon, Dec 12, 2016 at 11:20 AM, Peter Burgess |
Date | 2016-12-12 17:15 |
From | Steven Yi |
Subject | Re: can not understand the Array syntax |
Yes, I think that sums it up. As a sidenote, there was an issue I had filed for CS7 but closed: https://github.com/csound/csound/issues/447 but this might be a potential use case. Do you think having a declare option would be of use to you for this situation? On Mon, Dec 12, 2016 at 11:41 AM, Anton Kholomiov |
Date | 2016-12-12 17:19 |
From | Peter Burgess |
Subject | Re: can not understand the Array syntax |
Nice! I'm looking forward to what new things CS7 brings to the table :D So is that available for download and testing already? On Mon, Dec 12, 2016 at 5:15 PM, Steven Yi |
Date | 2016-12-12 20:29 |
From | joachim heintz |
Subject | Re: can not understand the Array syntax |
yes i expected an error, too, and i think you explained clearly why it should. joachim On 12/12/16 17:34, Steven Yi wrote: > I did a quick test and it looks like that actually works alright. (I > was expecting a compilation error myself.) > > I think that the parser code finds the "kArr2[]" and parses it as > "kArr2" with metadata the var is an array. The metadata would be used > on first-encounter with kArr2 and ignored if found again. However, > this seems like a bug, as is demonstrable with the following code: > > |
Date | 2016-12-12 20:39 |
From | Steven Yi |
Subject | Re: can not understand the Array syntax |
I've filed issue #728 to track this: https://github.com/csound/csound/issues/728 and have assigned it to the 6.x milestone so that it will be done for CS6. On Mon, Dec 12, 2016 at 3:29 PM, joachim heintz |