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 {
|...args|
^this.play(*args)
}
}
This doesnāt remove existing play
methods however.
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.

Is there a simple way to rename or make an alias of a method?
One way is:
this.preProcessor_
{
|code| if(code.contains(".alias")){code=code.replace(".alias",".play")}
}
;{ Saw.ar }.alias
foobar
will keep args
in an array. The * passes them as single arguments to play
rather than passing an array of arguments.
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:
ĻλαĻ
{
|...args|
^this.ĻλαĻ
(*args)
}
}
But this does
this.preProcessor_
{
|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:
this.preProcessor=PreProcessor.new.startDelimiter_("*:").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.
s.boot
;
this.preProcessor_{|code|
if( code includesAny:
[
$Ī» , $α , $Ļ
, $Ļ
],
{[
".ĻλαĻ
" , ".play",
".Ļ
αλĻ" , ".next"
]
.pairsDo
{
|key val| code=replace(code,key,val)
}
})
;code.inform
// ;code /*critical*/
}
;
{Saw.ar}.ĻλαĻ
;
{Saw.ar}.play
I was groping in the dark until I discovered itās ending resolution by perfect chanceā¦

It appears critical for
this.preProcessor
to return its argument value.
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.
hjh
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

Why do we need the
if
? Secondly what is the meaning of the$
in$Ī»
?
@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.

I canāt quite make head or tail of that quarkā¦
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.