On Saturday 18.12.2010 03:03:06 Greg Ewing wrote:
Eike Welk wrote:
| {| a, b |} -> # Attribute existence and access
is far too cryptic and does nothing to improve readability.
List comprehensions are also cryptic if you see them for the first time. The curly brackets with bars "{| |}" should symbolize that Python object are glorified dicts. It is also quite close to Ocaml's syntax for records. My secret agenda was however, to later introduce a new class and object syntax for Python. I just didn't dare to propose a completely revised Python. But here we go: :-) Class Creation -------------- Foo = class {| a, b |} This should be equivalent to: class Foo(object): def __init__(self, a, b): self.a = a self.b = b Inheritance is not so important in the context of classes that have no methods. It could be expressed with a new method ("inherits") of the metaclass. Like this: Foo = class {| a, b |}.inherits(Bar, Baz) How one would create methods, and if it should be possible to create method at all, needs to be discussed. Instance Creation ----------------- foo = {| a=1, b=2 |}:Foo This should be equivalent to: foo = Foo(a=1, b=2) In the usual case, it should not be necessary to specify the class name: foo = {| a=1, b=2 |} The run-time should search for a class with a matching "__init__" method. In case of ambiguities an exception would be raised. You have to name object attributes unambiguously for this to work. However it is more flexible than Ocaml because you can disambiguate it by specifying the class name. These constructions are expression, and can therefore be nested. The next nice idea from Ocaml would be extending the class system ... I'm getting a bit off topic though. I'll present a revised syntax for object access later; generalized constructors. Eike.