English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Ocaml compiler features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-01-16 (06:51)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Ocaml compiler features
On Mon, 2007-01-15 at 23:21 -0600, Edgar Friendly wrote:
> Richard Jones wrote:

> No, I want to make the following code legal:
> if y = 1 then
> 	print_int y;
> 	print_int z;
> else
> 	print_string "not one"
> It's just an unnecessary stumbling block for programmers coming from
> other languages.

So is your syntax:

	if cond1 then e1 
	elif cond2 then e2
	else el 

is THE correct, unambiguous, formulation, and what Felix uses <g>.
For procedural code:

	if cond do ..
	elif ..
	else ..

These forms were decided by Wirth after the Pascal ambiguities,
and his next attempt, Modula, uses them.

Felix also uses

	match .. with .. endmatch

but strangely has an open

	let .. in ...

whereas Standard ML uses

	let .. in .. end

Ocaml uses a closed form here:

	for .. do .. done

Felix, like C++, also has ; as a statement terminator
not a separator. Research was done on this (no I can't
cite it). Terminators are known to be better :)

Closed forms are precedence free, allow an unambiguous
grammar, and support easy cut and paste: all in all,
these syntaxen obey an important rule: the substitution

However, they lead to excess terminators, and so most languages
close some forms and leave others open.  IMHO Ocaml leaves
too many open, but this is just a minor taste issue: what
really interested me is the semantics.

BTW: Python solves the excess terminator problem by using indentation,
which is generally quite nice, IMHO, though it makes code containing
long quoted strings very ugly.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net