[Melbourne-pm] Arcane operators

Toby Corkindale toby.corkindale at strategicdata.com.au
Mon May 10 01:30:34 PDT 2010


On 10/05/10 12:52, Daniel Pittman wrote:
> Toby Wintermute<tjc at wintrmute.net>  writes:
>
>> (Background:
>> I've been playing with Scala every now and then, as I've mentioned before.
>> It has some nice advantages, like a great concurrency system, a good
>> OO implementation, and it's quite fast once the jvm gets warmed up.)
>>
>> I've noticed a worrying trend in Scala libraries though.
>> In Scala you can invent your own operators - they're just functions on
>> the objects with those names. And it seems that Unicode is valid too.
>
> Yay!  APL and A+!  How can you go past a language that supports things like:
>
>      x[⍋x←6?40]
>
> ...and the kids today complain that Perl and Emacs commands looks like line
> noise.  They don't know how good they have it.
>
> [...]
>
>> but for the most part, it feels like it's going a bit crazy.
>
> It probably is: the issue you mention is actually both less and more bad than
> the equivalent problem back in C++ when I worked there: back then you had a
> much more limited set of operators to overload, but the same enthusiasm for
> overloading them.
>
> The broader character set means that '*' is less likely to do something
> completely unexpected like "map", but you are more likely to see someone write
> APL style code.
>
>
>> In Perl it seems like the received wisdom is to back away from writing
>> code that looks like random line noise.
>
> APL is pretty much the extreme end of the Domain Specific Language spectrum,
> which is what operator overloading is a small step along the path to.
>
> Done right, this still is gold: you can't beat it.  It is still the killer
> advantage of Lisp, that it is so trivial to define a useful DSL, so you tend
> to do it all along the way.
>
> OTOH, done poorly DSL code is terrible.  Probably worse than, say, some of the
> "I don't understand OO and find Perl5 scary" Perl that I get to support.
>
>> If you could make up any operators you like, would you?
>
> Yes, absolutely.  I also 'use overload' in Perl.

So do I - but I'm overloading them within the original meaning.
ie. + is adding or appending, - is reducing, " is making a printable 
response, etc..

I am now tempted to create a library for Scala that entirely consists of 
smiley expressions, such as the sadface operator: a :( b
the snowman operator: c ☃ d
the wince operator: e >.< f
the mind boggles operator: g o.O h
and possibly the nethack operator:
a ║..{.d.. at .]K### b

hell, with enough custom operators, I could make a DSL for Nethack games.

? ( @ o.O @[Shopkeeper] ) { d => # }



-Toby


More information about the Melbourne-pm mailing list