I am modelling a programming language for fun, and the syntax is heavily influenced by Scala - specifically function definitions.
I have encountered a design problem because my language does not differentiate between functions defined via the
def syntax (class methods) and anonymous functions assigned to values (created using
=>) - it removes the differences in both implementation and behaviour.
The result is that the following two definitions mean the same thing:
def square(x: Int) = x*x
val square = (x: Int) => x*x
There is no reason for the latter form (immediate anonymous function assignment) to be used in any normal situation - it's simply possible to use it instead of the
Would having such duplicate syntax for defining named functions hurt the orthogonality of the language or some other design aspect?
I prefer this solution because it allows for short and intuitive definitions of methods and named functions (via
def), and short definitions of anonymous functions (using
Edit: Scala does differentiate between the two - anonymous functions are not the same as methods defined with
def in Scala. The differences are relatively subtle though - see the posts I linked before.