Implementing a language is easy, designing the syntax is hard!
August 23, 2009
One of the trickier problems of language design is the syntax. Right now I am wrestling with the syntax of anonymous functions in Heron.
One of the trickier problems of language design is the syntax. Right now I am wrestling with the syntax of anonymous functions in Heron.
I know that syntax is treated as not worthy of study by many computer scientists, but out in the real world good choices in language syntax I truly believe make or break a programming language.
I honestly believe that the s-expression syntax of Lisp and Scheme is a huge obstacle to its adoption, because it makes the language appear more exotic than they really are.
Right now, I am working on the syntax I want to use in my language Heron for passing anonymous functions to higher-order functions.
The C# syntax for this isn't too bad:
myHigherOrderFunction(
() <= { doSomething(); });
However, I find the obligatory "});" to be aesthetically displeasing. Also, it seems far too verbose compared to what I want to express.
What I really want to write is:
myHigherOrderFunction
{ doSomething(); };
This is convenient, but could be ambiguous for the reader. There are a lot of things that happen behind the scenes
- I create an anonymous function from a code block,
- I implicitly apply a function object to its argument.
In many curly-braced languages the "()" operator acts a function application operator. When we don't require the "()" operator in a language, we have implicit function application and usually with it implicit partial application. This is a feature of ML based languages (like OCaML and F#) which took me a long time to get used to.
So another option I am considering right now is having a secondary operator for applying functions.
The above example would then look like:
myHigherOrderFunction ->
() <= { doSomething(); };
This would be read as: apply the function myHigherOrderFunction to the anonymous function.
In the case of functions taking no arguments, it might make sense to allow omitting the "() <=".
So we would have:
myHigherOrderFunction ->
{ doSomething(); };
But now I am unhappy because we are either doing some black magic or we have a group of weird symobls "-> () <=". The only left-over advantage of the "->" operator is when performing partial application.
Oh well, like I said: designing the syntax is hard.
Related Reading
More Insights
INFO-LINK
| To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy. | |

