monte-language / typhon

A virtual machine for Monte.
Other
67 stars 10 forks source link

Decorator Pattern Syntax #186

Open MostAwesomeDude opened 7 years ago

MostAwesomeDude commented 7 years ago

This is not legal, but it should be:

object via (decorator) obj {}

The semantics are that the transformation would happen after auditing, during the binding of the object names to the closure and surrounding scope, and an exception would be raised if the match-bind fails. Yes, this means that decorator isn't evaluated until after auditing, and that this would be valid Kernel-Monte and not just valid Full-Monte.

dckc commented 7 years ago

Why should it be legal?

I can see some appeal, but I think it's important to count the cost every time we make the language bigger.

What's a motivating example to use in documentation, for example?

MostAwesomeDude commented 6 years ago

This is analogous to decorator syntax in Python or Java, and is in general an instance of the Decorator Pattern, aka the Wrapper Pattern, which is common in ocap designs as a way to annotate a particular instance of an object when doing membrane-style constructions like powerboxes, Horton, etc.

For us, it may occasionally be useful to do this technique, popular in older Java:

def via (buildingThing) thing.justOneCustomMethod(arg) { ... }

As a concrete example, consider building simple pumps:

def via (buildingSimplePump) myPump(input :Str) :List[Str] {
  return [for piece in (input.split(":") process(piece)]
}