From: luc.maranget@inria.fr (Luc Maranget)
To: Sanghyeon Seo <sanxiyn@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] break and continue for OCaml
Date: Thu, 10 Apr 2008 09:09:01 +0200 [thread overview]
Message-ID: <20080410070901.GA8177@yquem.inria.fr> (raw)
In-Reply-To: <5b0248170804091859s75c3f725s2db53f48fba6735c@mail.gmail.com>
> I have the first cut of patch to implement break and continue inside
> for and while loops for OCaml.
>
> http://sparcs.kaist.ac.kr/~tinuviel/devel/ocaml/
>
> Patch is against OCaml 3.10.2. All the meat is in bytecomp/bytegen.ml.
> Currently bytecode only. I am working on natvie code and error
> handling when break is used outside loop etc but I thought "releasing
> early" could be useful.
>
> What do you think?
I think that you can implement break/continue without altering
the lambda-code (file bytecomp/lambda.mli) by using the existing
'static exception' mechanism :
...
| Lstaticraise of (int * lambda list)
| Lstaticcatch of lambda * (int * Ident.t list) * lambda
...
with the following pretty printing convention (cf. option -dlambda)
(exit i) stands for 'Lstaticraise (i,[])'
(catch e1 with (i) e2) stands for 'Lstaticcatch (e1,(i,[]),e2)'
Then you have for instance
while e1 do e2 done ->
(catch
(while (e1) (catch e2 with (icont) ())
with (ibreak) ())
In the loop body e2, break is compiled into (exit ibreak)
and coninue into (exit icont).
It is a bit complicated, but then you get native code compilation for
free.
--
Luc
PS> I make no statement on whether break/continue
should be added to ocaml!
But..
1. Exceptions are already here and they express more flexible
control flow modifications.
2. Adding keywords is something that is not easily accepted,
because it breaks existing code.
next prev parent reply other threads:[~2008-04-10 7:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-10 1:59 Sanghyeon Seo
2008-04-10 7:09 ` Luc Maranget [this message]
2008-04-10 7:11 ` [Caml-list] " Jean-Christophe Filliâtre
2008-04-10 14:12 ` David Allsopp
2008-04-10 14:41 ` Richard Jones
2008-04-10 13:39 ` Richard Jones
2008-04-10 14:05 ` Martin Jambon
2008-04-10 14:19 ` Richard Jones
2008-04-10 14:24 ` Michael Wohlwend
2008-04-10 14:35 ` Martin Jambon
2008-04-10 14:38 ` Michael Wohlwend
2008-04-10 22:23 ` Florian Weimer
2008-04-10 20:35 ` Eric Cooper
2008-04-11 0:14 ` Micha
2008-04-11 3:44 Andrew I. Schein
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=20080410070901.GA8177@yquem.inria.fr \
--to=luc.maranget@inria.fr \
--cc=caml-list@inria.fr \
--cc=sanxiyn@gmail.com \
/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