I think the first one is a single function that has pattern matching for the parameter while the second one is defining the function twice and relying on the language to call the right one based on the parameter.
I think in Erlang the function identification is the name and the arity and this is as close I know of what you would like to have.
Semicolons separate partial definitions for a single function of a single arity, and periods end those definitions. Removing the punctuation might make parsing a bit more difficult (will there be more partial definitions?), so it's understandable to not offer it.
I'd imagine you could compile them both down to the same thing, as there has to be a conditional at some point to determine what code to run (unless there was some kind of dynamic dispatch), I think it's just a matter of preference
One one hand, this is yet another syntactic reskin of ideas from modern imperative-land. On the other hand, it looks like a good one, by a thoughtful author who also cares about integration with existing platforms, and that’s not nothing.
EG and Haxe share:
- compiles to Javascript
- Macros
- Pattern Matching
- async/await (Haxe requires a 3rd party macro lib, but it integrates well)
EG has:
- cleaner syntax
- document-building DSL
- "One of EG's primary goals is to be as compatible as possible with existing JavaScript libraries and frameworks and the node/iojs ecosystem." (Haxe makes compromises here to support other platforms)
Haxe has:
- static type-checking
- dead-code elimination
- support for more platform targets (PHP, Python, C#, Java and more)
- years of experience
I really like how the tooling to create a full application is already there, it isn't like "here's my new language, but there are no libraries, good luck!".
> Global variables need to be declared to be accessible:
> globals:
> document, google, React
If I'm getting this correctly, what a brilliant idea! Contain the shittiness by having one single location where all globals are declared. So very helpful.
But I agree, excellent set of features.
I think in Erlang the function identification is the name and the arity and this is as close I know of what you would like to have.
(some random link http://stackoverflow.com/questions/1050913/erlang-style-case...)
Deleted Comment
EG and Haxe share: - compiles to Javascript - Macros - Pattern Matching - async/await (Haxe requires a 3rd party macro lib, but it integrates well)
EG has: - cleaner syntax - document-building DSL - "One of EG's primary goals is to be as compatible as possible with existing JavaScript libraries and frameworks and the node/iojs ecosystem." (Haxe makes compromises here to support other platforms)
Haxe has: - static type-checking - dead-code elimination - support for more platform targets (PHP, Python, C#, Java and more) - years of experience
> Global variables need to be declared to be accessible: > globals: > document, google, React
If I'm getting this correctly, what a brilliant idea! Contain the shittiness by having one single location where all globals are declared. So very helpful.