Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Strange syntax behavior
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jdh30@c...>
Subject: Re: [Caml-list] Strange syntax behavior

> In the case of if...then...else, the else clause appears to consume only
> the first statement following.

Yes, it is looking for an expression:

if true then
  p "yes"
else
  p "no";
p "done";;

You may have meant:

if true then
  p "yes"
else
  begin
    p "no";
    p "done"
  end;;

> With try..with, the with clause appears 
> to consume everything it possibly can, despite even attempts to stop
> that with a begin..end clause.

Yes, it is looking for pattern matches.

try
  p "test"
with
  Not_found ->
    begin
      p "exc";
    end;
    p "done";;

You probably meant:

begin
  try
    p "test"
  with
    Not_found ->
      p "exc";
end;
p "done";;

> Is this a bug or a feature?  If a feature, why is this so?  the
> try..with behavior seems highly misleading.

I got a feeling for how these sorts of things work by looking at the 
indentation style (in emacs). It's fairly obvious that pattern matches 
(including "try ... with ..." as well as just "match ... with ...") need 
either brackets or "begin ... end" to nest them as, without this, the 
compiler couldn't tell which pattern was matching which match.

Cheers,
Jon.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners