Csound Csound-dev Csound-tekno Search About

[Csnd] Problem with goto?

Date2009-01-29 05:08
From"Art Hunkins"
Subject[Csnd] Problem with goto?
The simple .csd below does not render as I expect (the value of knum doesn't 
print to the screen).

When substituting "kgoto end" for "goto end", it renders as expected.

I'm at a loss as to why the original doesn't work, especially when it 
shouldn't seem to matter.

I run into this "code block" frequently, when processing the output of 
sensekey. I can easily program around it (including using kgoto instead of 
goto), but it "bugs" me.

And actually, I'm wondering if maybe it *is* a bug.

At any rate, any explanation?

Art Hunkins



-odac0



sr = 32000
ksmps = 100
nchnls = 2

instr 1

knum    = 10
        if knum > 0 goto next
; additional code goes here
        goto end
next:
 printk 1, knum

end:    endin




i1 0 60
e



 


Date2009-01-29 05:23
FromSteven Yi
Subject[Csnd] Re: Problem with goto?
Hi Art,

I ran this and got:

SECTION 1:
new alloc for instr 1:
PERF ERROR in instr 1: printk not initialised
        printk  1       knum    0

I think what is going on is that during the init pass, the knum > 0 is
not evaluating as the parser I think will see that it is a k-rate
comparison and will then use a krate version of "if".  So skipping
that at init time, it then moves to the "goto end" line and then skips
over initializing printk.  Then at performance time, the printk is not
initialized so it fails.

I changed the code to use if-then instead of if-goto, and the following works:


instr 1

knum    init 10

if knum > 0 then
    printk 1, knum
else
    ; additional code goes here
endif

endin


So I'm pretty sure that the explanation is correct, and it's a tricky
bit of code as it involves understanding how the parser works with if
statements to know what's going on.

If anyone sees something off with this explanation, please feel to correct me!

steven


On Wed, Jan 28, 2009 at 9:08 PM, Art Hunkins  wrote:
> The simple .csd below does not render as I expect (the value of knum doesn't
> print to the screen).
>
> When substituting "kgoto end" for "goto end", it renders as expected.
>
> I'm at a loss as to why the original doesn't work, especially when it
> shouldn't seem to matter.
>
> I run into this "code block" frequently, when processing the output of
> sensekey. I can easily program around it (including using kgoto instead of
> goto), but it "bugs" me.
>
> And actually, I'm wondering if maybe it *is* a bug.
>
> At any rate, any explanation?
>
> Art Hunkins
>
> 
> 
> -odac0
> 
> 
>
> sr = 32000
> ksmps = 100
> nchnls = 2
>
> instr 1
>
> knum    = 10
>       if knum > 0 goto next
> ; additional code goes here
>       goto end
> next:
> printk 1, knum
>
> end:    endin
>
> 
> 
>
> i1 0 60
> e
>
>
> 
> 
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>

Date2009-01-29 20:23
FromMike Moser-Booth
Subject[Csnd] Re: Re: Problem with goto?
Steven Yi wrote:
Hi Art,

I ran this and got:

SECTION 1:
new alloc for instr 1:
PERF ERROR in instr 1: printk not initialised
        printk  1       knum    0

I think what is going on is that during the init pass, the knum > 0 is
not evaluating as the parser I think will see that it is a k-rate
comparison and will then use a krate version of "if".  So skipping
that at init time, it then moves to the "goto end" line and then skips
over initializing printk.  Then at performance time, the printk is not
initialized so it fails.

I changed the code to use if-then instead of if-goto, and the following works:


instr 1

knum    init 10

if knum > 0 then
    printk 1, knum
else
    ; additional code goes here
endif

endin
  
I usually do it like this:

instr 1

knum = 10

if knum <= 0 goto end
printk 1, knum

end:
endin

That way you don't skip any lines at initialization and you don't have to bother with the extra lines of code for if...then chains. Just seems a little clearer to me.

.mmb


So I'm pretty sure that the explanation is correct, and it's a tricky
bit of code as it involves understanding how the parser works with if
statements to know what's going on.

If anyone sees something off with this explanation, please feel to correct me!

steven


On Wed, Jan 28, 2009 at 9:08 PM, Art Hunkins <abhunkin@uncg.edu> wrote:
  
The simple .csd below does not render as I expect (the value of knum doesn't
print to the screen).

When substituting "kgoto end" for "goto end", it renders as expected.

I'm at a loss as to why the original doesn't work, especially when it
shouldn't seem to matter.

I run into this "code block" frequently, when processing the output of
sensekey. I can easily program around it (including using kgoto instead of
goto), but it "bugs" me.

And actually, I'm wondering if maybe it *is* a bug.

At any rate, any explanation?

Art Hunkins

<CsoundSynthesizer>
<CsOptions>
-odac0
</CsOptions>
<CsInstruments>

sr = 32000
ksmps = 100
nchnls = 2

instr 1

knum    = 10
      if knum > 0 goto next
; additional code goes here
      goto end
next:
printk 1, knum

end:    endin

</CsInstruments>
<CsScore>

i1 0 60
e


</CsScore>
</CsoundSynthesizer>


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
csound"

    


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"