caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Eric Breck <ebreck@cs.cornell.edu>
To: caml-list@inria.fr
Subject: Re: On language extensions (was Re: [Caml-list] global record)
Date: Wed, 19 Jul 2006 21:12:39 -0400	[thread overview]
Message-ID: <51E3580C-02A1-4344-A5AA-862B580015F1@cs.cornell.edu> (raw)


> From: Daniel_Bünzli <daniel.buenzli@e...>
> Subject: On language extensions (was Re: [Caml-list] global record)
>
> Contrary to lisp's macros, each syntax extension is syntactically a
> new language. Hence not only do we need to learn a new semantics but
> also a new syntax. If I have to read someone else's code I want to
> read caml code and not caml code augmented with the author's
> syntactic obsessions.
>
> In code readability, there is a trade-off between succinctness and
> syntactic regularity. Camlp4 extensions increase the former but
> decrease the latter. For me camlp4's usage should be limited to real
> domain specific languages (e.g. like coq does) and research, it
> should not be used to increase ocaml's succinctness.

Succinctness is not precisely what I was after so much as locality -  
in this case, having each option declared in a single location - as  
opposed to the type definition in one place, the default value in  
another, the Arg.spec in another, code to print the chosen value of  
each option in another, and, optionally, the de-ref-ication in  
another.  Such locality is a basic principle of software engineering,  
and in this case I don't really know how to achieve it with only a  
library (and not a syntax extension).

I'm not advocating extending the language willy-nilly, but I feel  
that any new library already requires some amount of learning to use  
its particular API, and if a small, local extension to the language  
vastly shrinks (and localizes) code required to interface to the  
library, it seems reasonable to me (IMHO).

To put it another way, I do not agree with the adage that "syntactic  
sugar causes cancer of the semicolon." :)

As far as readability, I tried to choose syntax that would make clear  
to a casual reader what was going on, but clearly I'm blinded by  
having stared at this for awhile now.  As Nicolas Pouillard points  
out, you can always unsugar the code.

Anyway, I've been using variants of this library for half a year or  
so, and I've found it very convenient, so I thought I would offer it  
to others.

> This may be seen as a matter of personal taste: it is true that I
> lean towards syntactic regularity, i.e. less syntactic constructs.
> However there is another argument against using extensions: code
> maintenance. You have no guarantee that (1) an extension will not be
> broken by the next version of the language and (2) that the author
> will continue to maintain it.

I'm not sure why either 1 or 2 is more true for a syntax extension  
than for an arbitrary library, assuming the syntax extension doesn't  
try to make large-scale changes to the grammar.

> P.S. Even for domain specific languages many things can be done in
> pure ocaml by embedding the dsl in ocaml using meta-programming
> techniques.

I'm not sure what you mean here.  I understand meta-programming to  
mean (roughly) generating code programatically.  A solution along  
those lines to my problem (locality of command-line arguments) would  
be something like this: specify the options in some file, write some  
piece of code to process this and produce an ocaml file, which is  
then compiled and linked with the main program.  I actually  
originally did something along these lines, but then decided that  
since this approach also requires defining and processing a new  
syntax (of the option file), I would use camlp4 and integrate that  
syntax into my main program.  That is, camlp4 *is* meta-programming,  
it's just that it (a) integrates the DSL into the main program, and  
(b) hides the intermediate file.

But perhaps I'm misunderstanding your point - if you could clarify  
what you mean, I'd like to know what alternate approaches are.

Finally, I have the sense (perhaps I'm completely wrong) that the  
post I'm responding to was motivated in part by a thought that  
command-line option parsing is somehow not worthy of a domain- 
specific language / syntax extension.  I suppose it is something of a  
"syntactic obsession" with me to find a clear and concise way of  
specifying such options, since I write mostly small, command-line  
programs to which I want to be able to quickly add variant  
functionality.  Clearly, the benefit to any particular program is  
small - when you write enough of them, though, the lifetime savings  
in tearing-my-hair-out is, I think, a win.

best,

-E r i c

(PS: sorry if this doesn't get threaded appropriately, I read the  
digest of the list).


             reply	other threads:[~2006-07-20  1:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-20  1:12 Eric Breck [this message]
2006-07-20  5:16 ` skaller
2006-07-20  6:29   ` Stefano Zacchiroli
2006-07-20  8:57     ` Jean-Marie Gaillourdet
2006-07-20 12:42 ` Bünzli Daniel
2006-07-20 12:40   ` Camlp4 mysteries (was Re: On language extensions (was Re: [Caml-list] global record)) Martin Jambon
2006-07-20 23:38     ` Alain Frisch
2006-07-21  0:11       ` Martin Jambon
2006-07-21  0:29       ` skaller
2006-07-21  0:31       ` Martin Jambon
  -- strict thread matches above, loose matches on Subject: below --
2006-07-19 17:14 [Caml-list] global record Eric Breck
2006-07-19 19:41 ` On language extensions (was Re: [Caml-list] global record) Daniel Bünzli
2006-07-19 19:57   ` Richard Jones
2006-07-19 20:22     ` Stefano Zacchiroli
2006-07-19 21:33   ` Nicolas Pouillard
2006-07-20  2:57   ` Martin Jambon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51E3580C-02A1-4344-A5AA-862B580015F1@cs.cornell.edu \
    --to=ebreck@cs.cornell.edu \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).