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.
(
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 return nil and not just this string?"
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;
};
)
(
why does the preProcessor return nil when executing this block?
why oh why? it looks bad in my post window.
)
"and why does this return nil?"
Ctrl-Return goes through a method called “interpretPrintCmdLine” – meaning that it is going to interpret something and print the result. It is always going to interpret something, and always going to print something. "".interpret → nil.
The preprocessor function needs to return some code whose result will print something meaningful.
Thank you! I actually had a look at your project while investigating this, but as you say, it’s huge. A bit difficult to immediately understand how you do it. I will study it further.