Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] semi-colons and begin
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: [Caml-list] semi-colons and begin
> There are a lot of problems with the Caml-syntax and I can live with the
> most
> ones. I am really glad that Emacs indents correctly, and that makes the
> following
[...]
> My biggest problem is when the syntax error occurs in a completely different
> location in the file, because it makes finding the bugs very difficult.
> (I understand why the typechecker sometimes complains at the source,
> sometimes
> and the destination). Whould it be possible to pinpoint the error more
> exactly
> or is there a reason that in
> 
> let _ = 1+2;
> 
> let _ = 2
> 
> let _ = 4
> 
> we get a syntax error at the last 'let'?
> 
> /mattias
> 
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr

The reason is that your set of phrases

let _ = 1+2;

let _ = 2

let _ = 4

is understood as a single definition of a sequence expression as:

let _ =
  1 + 2;
  let _ = 2
  let _ = 4

hence the second ``let'' is is a local definition that needs an in
part that is lacking. Hence, the syntax error on the third let (the
parser is waiting for an ``in'' keyword, and finding ``let'' triggers
the syntax error).

The problem here is that there is no end-of-phrase marks that would
prevent the parser from shifting for ever. Hence, using explicit ends
of phrase here would be less error prone, although arguably a bit more
heavy since you would have to write:

1+2;;

2;;

4;;

On the other hand, you get rid of the ``let _ =''

Objective Caml supports those two styles, so you can choose the style
you prefer.

Hope this helps,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr