[PD] Patch acting weird with Pd 0.46.6
IOhannes m zmoelnig
zmoelnig at iem.at
Tue Jun 9 10:03:09 CEST 2015
On 2015-06-04 10:03, Pierre Massat wrote:
> The mistake I made
> was to believe that print would send the current value to the console at
> each step of the loop (like print in a for loop in Python for instance),
i meant to reply to this, but forgot.
i still cannot resist, so:
python actually behaves the same here, as shows the following
implementation:
<weirdo.py>
def find_slash(counter):
char = ord(string[counter - 1])
if char != 47:
find_slash(counter - 1)
print("output: %s" % (char))
print("counter: %s" % (counter))
counter = counter - 1
string = '/blabla/snare.wav'
find_slash(len(string))
</weirdo.py>
but most likely you wouldn't write your python code like that (apart
from the fact that in python you would just use "string.rfind('/')")
myself, i would write the code as something like
<noweirdo.py>
def find_slash(counter):
counter = counter - 1
print("counter: %s" % (counter))
char = ord(string[counter])
print("output: %s" % (char))
if char != 47:
find_slash(counter)
</noweirdo.py>
which is the same but has the order reversed
esp. the recursive call has moved to the very end of the function,
*after* all the print() (a common technique to exploit tail recursion
optimisation; probably that's the reason why i did it, dunno)
gmfsdr
IOhannes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20150609/6ff37170/attachment.sig>
More information about the Pd-list
mailing list