Channels ▼

Christopher Diggins

Dr. Dobb's Bloggers

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.


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 
  1. I create an anonymous function from a code block, 
  2. 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






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips 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.
 


Video