Tangent: Explicit Identifier Arguments

Published September 11, 2008
Advertisement
One of the main design focuses for Tangent as it stands now is to better allow Domain Specific Language (hereafter DSL) tendencies. Many of my primary motivations come from game programming where scripting languages are now ubiquitous. Even in the business world, there's been a proliferation of object modeling if not outright new DSLs made to try and take general programming languages and move them closer to the problems that programmers face.

And at least naively, it makes sense. The more naturally you can describe your solution (or problem depending on the language), the better that description will tend to be. Speaking the lingo of the domain you're working in helps that immensely. That's one of the reasons motivating Tangent's user definable operators (similar to Scala in that regard).


I talked earlier about including method definitions that are like phrases. These too tend around this motivator. In summary:
Orc smash Knight;

is acceptable Tangent syntax, presuming the smash operator is defined and suitable Orc and Knight instances are defined and in scope and everything. To make a preposition to that operation though:
Orc smash Knight with Boulder;

The original operation would need to return a method which takes the preposition (however you define it). Which is awkward, and kinda unreadable. So a better syntax might be:
public operator void smash(Actor Subject, GameObject Target);public operator void smash(Actor Subject, GameObject Target) (WeaponPreposition WeaponSuffix);// or public operator void smash(Actor Subject, GameObject Target) with (GameObject Weapon);


The final option seems (to me) to be the best in cases where the preposition can't be nicely abstracted. Too often I see method overloads (or simply ill-formed methods) where what the parameters do is inscrutable. Or the names suddenly become 'SmashTargetWithWeapon' which is informative, but (sometimes) overkill and not exceptionally readable to humans. Allowing explicit identifiers ('with' in the above example) to act as a overload selector or simply a descriptor to a parameter, people should be able to write more legible code. Ideally it'll be more descriptive too since some of the annoyances to being descriptive are removed and it's not difficult to write (like returning a intermediary method would be). And they allow the programmer to steer the syntax towards their domain.


The first step in getting that working is support for the explicit identifiers. The generation of intermediary types will come second. So I spent tonight implementing that general concept into Tangent. It touches a lot more things than I'd have thought, and was a little tricky to do in such a way that method picking still worked nicely, and the identifier tokens weren't picked up by the Any type. A bit still doesn't work. Binary operators don't recognize them, their precedence over alternatives during ambiguity isn't there, they don't actually work in method picking yet and probably a few other weird things.

But the example code for the evening:
public class foo{	public void bar me{                print "moo.";        }}public static void main(){	(new foo).bar me;     // moo.}


Next will come finishing these guys off, adding the intermediary types, and debugging. Then hopefully my whimsy shall turn more practical so I can do bug hunting and polish for all these damned features.
Previous Entry Tangent: Indexers
Next Entry Mini update.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement