Hey Mattias, It's because the .do
message returns the object to which it is sent, and a function
will return whatever the last statement evaluates to. Storing
the line of code you want to send to the interpreter in a
temporary variable "o" like you did should do the trick. The basic idea behind the preprocessor function is that you can take the incoming block of evaluated text, do whatever find/replace/parsing/side effects you want with it, and then as the final line of the function return the string you *do* want the interpreter to evaluate. best, Jonathan On 24/12/2018 00:35, emp@xxxxxxxxxxxxxx
wrote:
Is this false func thing about return context maybe? Returning outside of the do loop like this actually seems to work: ( thisProcess.interpreter.preProcessor = {|codeBlock| var o, b = codeBlock.split($\n); b.do{|code| c = code.split($ ); if(code.beginsWith("w" ), { c.scramble.postln; }, { o = code.replace("(").replace(")"); }); }; o; }; )23 dec. 2018 kl. 21:00 skrev emp@xxxxxxxxxxxxxx: Hi, I posted this question on the forum as well, but realize that maybe not that many use preProcessor on a daily basis, and not all of you are there so I’ll try here too. Sorry for the cross-posting. Trying to get my head tuned to the inner workings of Interpreter’s preProcessor. Maybe someone can explain why it always posts a nil in both the true func and the false func below? The true func works besides the ugliness of the nil post. The false func should just send the code to the regular interpreter, treating it as a normal sc line. It doesn’t. Thanks! Mattias ( thisProcess.interpreter.preProcessor = {|codeBlock| var b = codeBlock.split($\n); b.do{|code| c = code.split($ ); if(code.beginsWith("w" ), { c.scramble.postln; }, { code; }); }; }; ) ( why does the preProcessor return nil when executing this block? the scramble function obviously works. why oh why? it looks bad in my post window. ) "and why does this line return nil and not just this string?” _______________________________________________ sc-users mailing list info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx archive: https://listarc.bham.ac.uk/marchives/sc-users/ search: https://listarc.bham.ac.uk/lists/sc-users/search/_______________________________________________ sc-users mailing list info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx archive: https://listarc.bham.ac.uk/marchives/sc-users/ search: https://listarc.bham.ac.uk/lists/sc-users/search/ --
JC Reus WEB: jonathanreus.com |