caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jean-Denis Eiden" <jean-denis.eiden@orange.fr>
To: <caml-list@inria.fr>
Subject: [Caml-list] listes qui bouclent
Date: Sun, 7 Sep 2014 11:31:45 +0200	[thread overview]
Message-ID: <91F16B653D20446DA42F7B673FD5509D@PCdejd> (raw)

Bonjour à tous,

CaML light permet la construction suivante :

#let rec liste = 0::1::2::3::liste;;
liste : int list =
 [0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0;
  1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1;
  2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2;
  3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2;
  ...]

Cela étant, j'aimerais pouvoir faire la même chose en paramétrant la période 
; par exemple, j'aimerais créer [ 0 ; 1 ; 2 ; ... ; n-1 ; 0 ; 1 ; 2 ; ... ] 
:

#let repète n = let aux = ref [] in for i = n-1 downto 0 do aux:= i::(!aux) 
done; !aux;;
repète : int -> int list = <fun>

#let cyclique n = let aux = repète n in let rec liste = aux @ liste in 
liste;;

Mais là :

let cyclique n = let rec liste = (repète n) @ liste in liste;;
>                                           ^^^^^^^
Ce genre d'expressions n'est pas autorisé comme membre droit d'un "let rec".

Est-ce seulement un problème de syntaxe ou bien y a-t-il impossibilité 
absolue, la taille de la liste servant de période devant être connue à la 
compilation ?

Cordialement, Jean-Denis Eiden


             reply	other threads:[~2014-09-07  9:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-07  9:31 Jean-Denis Eiden [this message]
2014-09-07  9:55 ` Rémy Besognet
2014-09-07 13:24 ` Jeremy Yallop

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=91F16B653D20446DA42F7B673FD5509D@PCdejd \
    --to=jean-denis.eiden@orange.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;
as well as URLs for NNTP newsgroup(s).