apoch / epoch-language

Home of the Epoch Programming Language Project
Other
72 stars 3 forks source link

Allow overloaded constructors #87

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently all constructors require that all structure members be explicitly 
initialized. While this is fine for trivial cases, it will not suffice for 
general purpose use.

Add support for a constructor tag that flags an overloaded function as being a 
constructor, i.e. that creates a bound local variable in the appropriate scope. 
This should be trivial to accomplish by hooking the existing compile-time 
helper and tagging mechanisms.

Syntax should resemble the following:

structure Foo :
(
   integer(NumericField),
   string(TextField),
   boolean(FlagField)
)

Foo : (identifier(variablename)) -> (Foo(0, "default", false)) 
[constructor(variablename)]

entrypoint : () -> ()
{
   // Construct the "normal" explicit way
   Foo(normal, 42, "test", true)

   // ... and now construct using the overloaded constructor defined above
   Foo(usesdefaults)

   debugwritestring(normal.TextField)        // outputs "test"
   debugwritestring(usesdefaults.TextField)  // outputs "default"
}

Original issue reported on code.google.com by don.ap...@gmail.com on 20 Dec 2010 at 6:40

GoogleCodeExporter commented 9 years ago
Corrected labels.

Original comment by don.ap...@gmail.com on 20 Dec 2010 at 6:40

GoogleCodeExporter commented 9 years ago
Implementation committed.

Original comment by don.ap...@gmail.com on 25 Dec 2010 at 4:28