From: Pascal Zimmer <zimmer@easynet.fr>
To: caml-list@inria.fr
Subject: Instruction return
Date: Sat, 31 May 1997 10:30:20 -0700 [thread overview]
Message-ID: <3390602C.20BB@easynet.fr> (raw)
Serait-il possible d'ajouter une instruction return au langage CAML afin
de pouvoir sortir directement d'une boucle, comme c'est le cas en C ? Je
pense qu'une telle instruction ameliorerait beaucoup la lisibilite du
code.
Par exemple, cela permettrait de retourner la valeur d'une fonction au
cours d'une boucle for, alors que pour l'instant on doit utiliser une
boucle while avec un compteur sous forme de pointeur.
Ainsi, une fonction classique de recherche d'une valeur x dans un tableau
non trie v s'ecrit:
let rech x v =
let n = vect_length v in
let i = ref 0 in
while !i < n & v.(!i) <> x do i := !i + 1 done;
not (!i = n);;
Avec une instruction return, on pourrait l'ecrire ainsi:
let rech x v =
let n = vect_length v in
for i=0 to n-1 do
if v.(i) = x then return true
done; false;;
Cette derniere forme sans pointeur pour le compteur i est tout de meme
plus claire !
Bien entendu, le typeur devra verifier que le type renvoye par return est
le meme que celui renvoye par la derniere instruction de la fonction.
Une telle possibilite (renvoi par return ou par la derniere instruction)
est par exemple utilisee par le langage de programmation de MAPLE, sauf
qu'il n'y a aucun controle de type.
J'aimerais donc savoir si une telle instruction est possible ou s'il y a
incompatibilite avec le reste du langage.
[English: Is it possible to add a 'return' instruction to the CAML
language, like in C ?]
next reply other threads:[~1997-06-02 14:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-05-31 17:30 Pascal Zimmer [this message]
1997-06-02 14:15 ` Pierre Weis
1997-06-03 8:37 ` Vincent Poirriez
1997-06-03 10:24 ` Pierre Weis
1997-06-03 14:17 ` Vincent Poirriez
1997-06-02 16:23 Dwight VandenBerghe
1997-06-02 21:41 ` Pierre Weis
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=3390602C.20BB@easynet.fr \
--to=zimmer@easynet.fr \
--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