[Cs-dev] Fun with multiple assign
Date | 2010-02-12 17:49 |
From | jpff |
Subject | [Cs-dev] Fun with multiple assign |
A small puzzle for you all -- I got it right before running it iv1, iv2, = 5, 6 iv1, iv2 = iv2, iv1; print iv1 print iv2 iv1, iv2, = 5, 6 iv1, iv2 = iv2+1, iv1+1; print iv1 print iv2 What values are printed? ==John ffitch PS This could be a reason not to allow this! ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2010-02-12 17:56 |
From | Steven Yi |
Subject | Re: [Cs-dev] Fun with multiple assign |
Well, at first glance it looks like it should print: 6 5 7 6 but my guess from your email is that the expressions don't work as expected, so perhaps: 6 5 7 8 ? On Fri, Feb 12, 2010 at 12:49 PM, jpff |
Date | 2010-02-12 17:56 |
From | Rory Walsh |
Subject | Re: [Cs-dev] Fun with multiple assign |
6 5 7 6? But that's the obvious answer so I'm guessing it's not right! On 12 February 2010 17:49, jpff |
Date | 2010-02-12 18:20 |
From | jpff@cs.bath.ac.uk |
Subject | Re: [Cs-dev] Fun with multiple assign |
> 6 5 7 6? But that's the obvious answer so I'm guessing it's not right! > > To put you out of your misery the answer is instr 1: iv1 = 6.000 instr 1: iv2 = 6.000 instr 1: iv1 = 7.000 instr 1: iv2 = 6.000 Now explain! Really is esay if you understand how Csound works...... ==John ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2010-02-12 18:23 |
From | jpff@cs.bath.ac.uk |
Subject | Re: [Cs-dev] Fun with multiple assign |
PS: I do know how the "fix" but it may slow down all assignments a bit >> 6 5 7 6? But that's the obvious answer so I'm guessing it's not right! >> >> > > To put you out of your misery the answer is > > instr 1: iv1 = 6.000 > instr 1: iv2 = 6.000 > instr 1: iv1 = 7.000 > instr 1: iv2 = 6.000 > > > Now explain! Really is esay if you understand how Csound works...... > > ==John > > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > Csound-devel mailing list > Csound-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/csound-devel > > > ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2010-02-12 19:47 |
From | Victor Lazzarini |
Subject | Re: [Cs-dev] Fun with multiple assign |
No. On 12 Feb 2010, at 18:23, jpff@cs.bath.ac.uk wrote: > PS: I do know how the "fix" but it may slow down all assignments a bit > >>> 6 5 7 6? But that's the obvious answer so I'm guessing it's not >>> right! >>> >>> >> >> To put you out of your misery the answer is >> >> instr 1: iv1 = 6.000 >> instr 1: iv2 = 6.000 >> instr 1: iv1 = 7.000 >> instr 1: iv2 = 6.000 >> >> >> Now explain! Really is esay if you understand how Csound works...... >> >> ==John >> >> >> ------------------------------------------------------------------------------ >> SOLARIS 10 is the OS for Data Centers - provides features such as >> DTrace, >> Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW >> http://p.sf.net/sfu/solaris-dev2dev >> _______________________________________________ >> Csound-devel mailing list >> Csound-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/csound-devel >> >> >> > > > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as > DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > Csound-devel mailing list > Csound-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/csound-devel ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2010-02-12 19:55 |
From | Steven Yi |
Subject | Re: [Cs-dev] Fun with multiple assign |
Well, I'm assuming then that all the iv1's and iv2's are all pointing to the same address rather than using any temporary memory address between read and writes. If so, that'd explain the first two 6's as it'd get processed like: iv1 = iv2 iv2 = iv1 The fix you were talking about, should it be that all of the right hand args should be read first and stored in temp variables before assigning to left-hand args? steven On Fri, Feb 12, 2010 at 1:20 PM, |
Date | 2010-02-12 19:56 |
From | andy fillebrown |
Subject | Re: [Cs-dev] Fun with multiple assign |
wow, i got it right. the order of operations i surmised... iv1 = 5 iv2 = 6 iv1 = iv2 iv2 = iv1 iv1 = 5 iv2 = 6 iv1_internal = iv2 + 1 iv2_internal = iv1 + 1 iv1 = iv2_internal iv2 = iv1_internal On Fri, Feb 12, 2010 at 2:47 PM, Victor Lazzarini |
Date | 2010-02-12 21:04 |
From | fons@kokkinizita.net |
Subject | Re: [Cs-dev] Fun with multiple assign |
Attachments | None |
Date | 2010-02-12 21:15 |
From | DavidW |
Subject | Re: [Cs-dev] Fun with multiple assign |
On 13/02/2010, at 8:04 AM, fons@kokkinizita.net wrote: > Python gets that right: > > a,b = b,a > > will swap the values of a and b. Not quite = depends on the mutability of a and b. Won't work for tuples for eg. D. ________________________________________________ Dr David Worrall. - Experimental Polymedia: worrall.avatar.com.au - Sonification: www.sonifiction.com.au - Education for Financial Independence: www.mindthemarkets.com.au ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2010-02-12 21:52 |
From | fons@kokkinizita.net |
Subject | Re: [Cs-dev] Fun with multiple assign |
Attachments | None |
Date | 2010-02-12 22:45 |
From | jpff@cs.bath.ac.uk |
Subject | Re: [Cs-dev] Fun with multiple assign |
You win a coconut! But you did not ecplsin the second case! > Well, I'm assuming then that all the iv1's and iv2's are all pointing > to the same address rather than using any temporary memory address > between read and writes. If so, that'd explain the first two 6's as > it'd get processed like: > > iv1 = iv2 > iv2 = iv1 > > The fix you were talking about, should it be that all of the right > hand args should be read first and stored in temp variables before > assigning to left-hand args? > > steven > > On Fri, Feb 12, 2010 at 1:20 PM, |
Date | 2010-02-12 22:46 |
From | jpff@cs.bath.ac.uk |
Subject | Re: [Cs-dev] Fun with multiple assign |
> wow, i got it right. > You win the first prize! Such fun! > the order of operations i surmised... > > iv1 = 5 > iv2 = 6 > iv1 = iv2 > iv2 = iv1 > iv1 = 5 > iv2 = 6 > iv1_internal = iv2 + 1 > iv2_internal = iv1 + 1 > iv1 = iv2_internal > iv2 = iv1_internal > > > On Fri, Feb 12, 2010 at 2:47 PM, Victor Lazzarini > |