Rename or alias method?

Is there a simple way to rename or make an alias of a method? For instance, if I wanted to rename the .play method everywhere to .foobar?

+Object {
   foobar {

This doesn’t remove existing play methods however.

1 Like

Great, thanks! Actually, that’s fine, I wouldn’t want to remove the existing method.

What does the * signify in this setting?

It allows every element in array to be unpacked & passed successively as comma separated values.

One way is:

	|code| if(code.contains(".alias")){code=code.replace(".alias",".play")}

;{	}.alias
1 Like

foobar will keep args in an array. The * passes them as single arguments to play rather than passing an array of arguments.

1 Like

Ok, I should let on what I’m up to! For a particular project, I wanted to see if I could livecode in a sort of reverse ‘Gringlish’ – using the Greek alphabet to code in instead of Latin.

This didn’t parse:

   πλαυ {

But this does :slight_smile:

	|code| if(code.contains(".πλαυ")){code=code.replace(".πλαυ",".play")}


I’ve also been able to use EventShortcuts from the miSCellaneous library to be able, for instance, to write \amp in an event as α


That’s sick… check this out:

A live coding language written in one-line:"*:").endDelimiter_(":*");x=(lang:\xoxo,languages:(xoxo:{|c,e|var v=c.split($:),o=Pbind(\amp,Pseq(v[1].asList.collect{|q|(q.asString=="x").binaryValue},inf),\instrument,v[0].asSymbol,\dur,1/4);e.put(\xo,o)}))

It requires PreProcessor, this is for you.

I’m not currently aware of any embedded live-coding languages using only the core library.

I’ve also never ventured far into these waters, and so I decided to attempt it using this as an example.

This was… difficult, even though it looks simple.

It appears critical for this.preProcessor to return it’s argument value.

	if( code includesAny:
			$λ , $α , $υ , $π
			".πλαυ" , ".play",
			".υαλπ" , ".next"
			|key val| code=replace(code,key,val)
	// ;code /*critical*/

I was groping in the dark until I discovered it’s ending resolution by perfect chance…

Not exactly – if you return the input argument value, then the interpreter will try to run the original string, which will choke on nonstandard syntax.

The preprocessor should return a string containing the final code to execute. (Admittedly this is not stated directly in the documentation – I’m surprised to see that actually.)

In the posted example, the value of the code variable is being modified. So returning code from the function is returning the new string – and not the argument value.

Just wish to be precise, to avoid confusion.


I’m glad to see that this odd project of mine has interest from people much better at coding than I am! I’ll work through the suggestions here when I get time and see how I get on.

I can’t quite make head or tail of that quark, but Rainer’s core library solution is working for me so far, thanks!

Two things I don’t understand. Why do we need the if? Secondly what is the meaning of the $ in ?

the $ is how you indicate a character. “r” is a String of length 1. its first element is Char($r)

a = "r";
a.class // String
a // r
a[0] // r
a[0].class // Char

the if clause is optional - if the string you hope to replace is present it wastes a few cycles, if not it saves a few

@semiquaver answered perfectly…The if conditional is included as an optional efficiency statement, and while it may be slightly verbose for brief demonstrations, it could also allow one to sensibly introduce such an alias set into a more expanded workflow.

This has the potential to yield excellent results… especially in the case of using a character set that SC would not understand in any other context.

The characters used here (with the if, mandatory) would make a very efficient set of custom commands, in startup.scd.

It’s very difficult to decipher… I’ve come to understand that it mostly extends the core .preProcessor functionality, by allowing one to define a hierarchy of languages embedded within languages, as well as the ability to call specific translations, without necessarily (I believe) affecting the client/interpreter .preProcessor directly.

It’s good to know every option… but unfortunately that quark is rather poorly documented, and far beyond your current use case (it seems) at any rate.