[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] preProcessor woes



Yes, that seems reasonable. Thanks!
/m

28 dec. 2018 kl. 18:31 skrev info@xxxxxxxxxxxxxxxx:

Hey Matthias,

Ah, I see the confusion you're having. As far as I understand it, the return value of the preprocessor function needs to be a string of SuperCollider code in order to be evaluated. I'm not sure exactly how it's implemented, but my guess is that the behavior is very similar to the interpret message of the Interpreter.. or may even use this method outright. Someone please correct me if I'm wrong. 

The interpret method expects a string as input.

this.interpret("20+40") // yields 60 in the post window

Anything other than a string will not be interpreted.

this.interpret(378) // yields nil in the post window

best,

Jonathan


On 28/12/2018 15:32, emp@xxxxxxxxxxxxxx wrote:
Hi Jonathan,

Thanks! Yes, I’m beginning to realize that maybe I’m using the preProcessor in an inefficent way. I guess I’m doing all I can to avoid digging into the confusing world of regExp.. ;)
I still don’t really understand the nil return though. If it’s b that gets returned it should be an array, right? Is it preProcessor that replaces everything but strings with nil? Explicitly returning b.asString seems to work though (if is’t valid sc code).

Now reading up on regExp.

/m

26 dec. 2018 kl. 17:55 skrev info@xxxxxxxxxxxxxxxx:

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


--
JC Reus

WEB: jonathanreus.com