[Csnd] Macro interpolation confusion
| Date | 2019-06-28 10:44 |
| From | boonier |
| Subject | [Csnd] Macro interpolation confusion |
Hi, could someone please clarify for me what is valid for dynamically
creating variable names and strings in a macro:
This for example will throw an error:
#define TRKCONTROLS(NUM) #
gkTrk$NUM_Start = chndler("Trk$NUM_Start")
gkTrk$NUM_End = chndler("Trk$NUM_End")
gkTrk$NUM_Instr = chnget("Trk$NUM_Instr")
#
$TRKCONTROLS(0)
Whereas, this will compile fine:
#define TRKCONTROLS(NUM) #
gkTrkStart_$NUM = chndler("TrkStart_$NUM")
gkTrkEnd_$NUM = chndler("TrkEnd_$NUM")
gkTrkInstr_$NUM = chnget("TrkInstr_$NUM")
#
$TRKCONTROLS(0)
(chndler is a UDO)
Do arguments need to be placed always at the end of the variable or string?
Further to this, I note that a number of the McCurdy examples suffer from
the same issues of macro argument interpolation errors
(DrumSequencerVariableLength is one example).
Has something changing in the parser in recent versions?
Many thanks
--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
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 | 2019-06-28 11:31 |
| From | John ff |
| Subject | Re: [Csnd] Macro interpolation confusion |
I think the issue is what ends a macro name. It is a dot or a character that cannot be part of a macro name. Yes much has changed in the pre lexer where macros are expanded Sent from TypeApp On Jun 28, 2019, 10:55, at 10:55, boonier |
| Date | 2019-06-28 11:41 |
| From | Iain McCurdy |
| Subject | Re: [Csnd] Macro interpolation confusion |
|
In your version which throws an error, suffixing 'NUM' with a '.' will prevent the error.
So this will work:
#define TRKCONTROLS(NUM) #
gkTrk$NUM._Start = chndler("Trk$NUM._Start") gkTrk$NUM._End = chndler("Trk$NUM._End") gkTrk$NUM._Instr = chnget("Trk$NUM._Instr") # $TRKCONTROLS(0)
The dot functions as an escape.
You are correct in noting that in earlier versions of Csound this was not necessary, but its inclusion makes the macro syntax more robust.
I.
From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of boonier <smills@ROOTSIX.NET>
Sent: 28 June 2019 09:44 To: CSOUND@LISTSERV.HEANET.IE Subject: [Csnd] Macro interpolation confusion Hi, could someone please clarify for me what is valid for dynamically
creating variable names and strings in a macro: This for example will throw an error: #define TRKCONTROLS(NUM) # gkTrk$NUM_Start = chndler("Trk$NUM_Start") gkTrk$NUM_End = chndler("Trk$NUM_End") gkTrk$NUM_Instr = chnget("Trk$NUM_Instr") # $TRKCONTROLS(0) Whereas, this will compile fine: #define TRKCONTROLS(NUM) # gkTrkStart_$NUM = chndler("TrkStart_$NUM") gkTrkEnd_$NUM = chndler("TrkEnd_$NUM") gkTrkInstr_$NUM = chnget("TrkInstr_$NUM") # $TRKCONTROLS(0) (chndler is a UDO) Do arguments need to be placed always at the end of the variable or string? Further to this, I note that a number of the McCurdy examples suffer from the same issues of macro argument interpolation errors (DrumSequencerVariableLength is one example). Has something changing in the parser in recent versions? Many thanks -- Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html 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 | 2019-06-28 11:54 |
| From | Si Mills |
| Subject | Re: [Csnd] Macro interpolation confusion |
ahh splendid, good to know, yes that works thanks you Is this in the docs somewhere that I've missed? On Fri, 28 Jun 2019 at 11:41, Iain McCurdy <i_mccurdy@hotmail.com> wrote:
|
| Date | 2019-06-28 19:40 |
| From | Tobiah |
| Subject | Re: [Csnd] Macro interpolation confusion |
Would it be difficult to accept "Trk${NUM}_Start"? That seems
so much more familiar and readable to me. As it is, if you really
want a dot in the name, do you have to do "Trk$NUM.._Start"?
On 6/28/19 3:41 AM, Iain McCurdy wrote:
> In your version which throws an error, suffixing 'NUM' with a '.' will prevent the error.
> So this will work:
>
> #define TRKCONTROLS(NUM) #
> gkTrk$NUM._Start = chndler("Trk$NUM._Start")
> gkTrk$NUM._End = chndler("Trk$NUM._End")
> gkTrk$NUM._Instr = chnget("Trk$NUM._Instr")
> #
> $TRKCONTROLS(0)
>
> The dot functions as an escape.
> You are correct in noting that in earlier versions of Csound this was not necessary, but its inclusion makes the macro syntax more robust.
>
> I.
>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *From:* A discussion list for users of Csound |
| Date | 2019-06-28 20:05 |
| From | john |
| Subject | Re: [Csnd] Macro interpolation confusion |
A dot is not valid in a name but otherwise yes yo need two dots, one to
terminate the macro andthenthe dot you want
Not thouht about how hard ${NUM} would be but the macro expansion code
is already very complex. { has other meanngs as well
On Fri, 28 Jun 2019, Tobiah wrote:
> Would it be difficult to accept "Trk${NUM}_Start"? That seems
> so much more familiar and readable to me. As it is, if you really
> want a dot in the name, do you have to do "Trk$NUM.._Start"?
>
> On 6/28/19 3:41 AM, Iain McCurdy wrote:
>> In your version which throws an error, suffixing 'NUM' with a '.' will
>> prevent the error.
>> So this will work:
>>
>> #define TRKCONTROLS(NUM) #
>> gkTrk$NUM._Start = chndler("Trk$NUM._Start")
>> gkTrk$NUM._End = chndler("Trk$NUM._End")
>> gkTrk$NUM._Instr = chnget("Trk$NUM._Instr")
>> #
>> $TRKCONTROLS(0)
>>
>> The dot functions as an escape.
>> You are correct in noting that in earlier versions of Csound this was not
>> necessary, but its inclusion makes the macro syntax more robust.
>>
>> I.
>>
>>
>> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>> ---
>> *From:* A discussion list for users of Csound |
| Date | 2019-06-28 20:15 |
| From | john |
| Subject | Re: [Csnd] Macro interpolation confusion |
PS i seems tat te use of dot to terminate a macro name is not clearly
stated. I will see if I can find some words for it.
==John ff
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 |