Csound Csound-dev Csound-tekno Search About

Re: macros

Date1998-04-19 16:23
Fromrasmus ekman
SubjectRe: macros
Christopher Neese wrote:
>  
       

Why couldn't you use this:

;*******************Example orc:

#define EXAMPLE(OUT#N) #
        kunique$N.r0      init    0
        kunique$N.r1      init    0
        kunique$N.r2      init    0
        kunique$N.r2       =       kunique$N.r1
        kunique$N.r1       =       kunique$N.r0
        kunique$N.r0       =       int(rnd(1000))
        ;code using kunique$N.r2, kunique$N.r1, kunique$N.r0 and defining OUT
        #       ;end of macro

instr 1

    k1      init    0
    k2      init    0

    $EXAMPLE(k1#1)
    $EXAMPLE(k2#2)

;etc.


	re


> ;**********************Parsed orc:
> 
> instr 1
> 
> k1      init    0
> k2      init    0
> 
>         kunique1r 0     init    0
>         kunique1r 1     init    0
>         kunique1r 2     init    0
>         kunique1r2      =       kunique1r1
>         kunique1r1      =       kunique1r0
>         kunique1r0      =       int(rnd(1000))
>         ;code using kunique1r2, kunique1r1, kunique1r0 and defining k1
> 
>         kunique2r 0     init    0
>         kunique2r 1     init    0
>         kunique2r 2     init    0
>         kunique2r2      =       kunique2r1
>         kunique2r1      =       kunique2r0
>         kunique2r0      =       int(rnd(1000))
>         ;code using kunique2r2, kunique2r1, kunique2r0 and defining k2
> 
> ;etc.

Date1998-04-19 21:17
FromChristopher Neese
SubjectRE: macros
This is an interesting solution, and it works really well.

I'm not sure it is as fool-proof as what I had in mind, but perhaps it is
more powerful.

It has several advantages:
1.	Any variable name you want to be unique you just end with a $N.  So you
can have as many names as you want.
2.	If you want macros to share variables, you can feed them the same N.
Thus you can have macro pairs.  (like READ and WRITE)

The system has these problems:
1. Advanced macros can only take 5 arguments.  (can anyone justify this
number?)  N reduces this number to 4.
2. N should always be replaced by a number for safety.  If you have asiga$N
in one macro, and asig$N in another macro, they expand to the same thing if
n is 1 in the first case and a1 in the second case.  (a numbering scheme
like a1, a2, a3, etc.  isn't so far fetched after all.)
3. Similar to 2.,  the text before $N shouldn't end in a number. .  If you
have asig1$N in one macro, and asig$N in another macro, they expand to the
same thing if n is 1 in the first case and 11 in the second case.
4. You need to make sure you don't accidentally repeat N.  (not totally
fool-proof)

Disadvantage number 1 is really the most annoying, but there is something to
be said for fool-proofing. Most of us are fools if we have been working late
enough.  :)

If $N were considered special parameter in advanced macros (one that was
optional, and if omitted would be replaced by some LARGE UNIQUE integer),
then your system would be very fool-proof and more powerful than mine.  I'd
like to see that 5-parameter thing raised to something like 20 at least.
After all, look at how many parameters some of our opcodes take!

Pretty much, I want my macros to have unique variable names 99.5% of the
time.  That way I can use whatever variable name I want in the orc without
worrying about messing up the macroed code.  After all, I'm looking at a
macro as code that doen't get messed with very often.  I want to use macros
for things I do a lot, but don't' justify their own opcode written in C.




Christopher Neese

-----Original Message-----
From:	rasmus ekman [mailto:rasmuse@hem.passagen.se]
Sent:	Sunday, April 19, 1998 11:24 AM
To:	Christopher Neese
Cc:	Csound
Subject:	Re: macros

Christopher Neese wrote:
>


Why couldn't you use this:

;*******************Example orc:

#define EXAMPLE(OUT#N) #
        kunique$N.r0      init    0
        kunique$N.r1      init    0
        kunique$N.r2      init    0
        kunique$N.r2       =       kunique$N.r1
        kunique$N.r1       =       kunique$N.r0
        kunique$N.r0       =       int(rnd(1000))
        ;code using kunique$N.r2, kunique$N.r1, kunique$N.r0 and defining
OUT
        #       ;end of macro

instr 1

    k1      init    0
    k2      init    0

    $EXAMPLE(k1#1)
    $EXAMPLE(k2#2)

;etc.


	re


> ;**********************Parsed orc:
>
> instr 1
>
> k1      init    0
> k2      init    0
>
>         kunique1r 0     init    0
>         kunique1r 1     init    0
>         kunique1r 2     init    0
>         kunique1r2      =       kunique1r1
>         kunique1r1      =       kunique1r0
>         kunique1r0      =       int(rnd(1000))
>         ;code using kunique1r2, kunique1r1, kunique1r0 and defining k1
>
>         kunique2r 0     init    0
>         kunique2r 1     init    0
>         kunique2r 2     init    0
>         kunique2r2      =       kunique2r1
>         kunique2r1      =       kunique2r0
>         kunique2r0      =       int(rnd(1000))
>         ;code using kunique2r2, kunique2r1, kunique2r0 and defining k2
>
> ;etc.

Date1998-04-19 21:56
FromNicola Bernardini
SubjectRe: macros
On Sun, 19 Apr 1998, rasmus ekman wrote:

> Christopher Neese wrote:
> >  
>        
> 
> Why couldn't you use this:
> 
> ;*******************Example orc:
> 
> #define EXAMPLE(OUT#N) #
>         kunique$N.r0      init    0
>         kunique$N.r1      init    0
>         kunique$N.r2      init    0
...
[snip]

why could'nt we use the cpp pre-processor? It's already there,
it works well, and it could be spawned by csound itself before
parsing... (furthermore, it's available on all platforms, source code
is available so it could reasonably be modified to add csound-specific
features if necessary, etc. etc. etc.). I did'nt dare say this before,
but since we're evidently going in that direction...

Nicola

------------------------------------------------------------------------
Nicola Bernardini
E-mail: nicb@axnet.it
 
Re graphics: A picture is worth 10K words -- but only those to describe
the picture.  Hardly any sets of 10K words can be adequately described
with pictures.