From: Pierre Weis <Pierre.Weis@inria.fr>
Message-Id: <199910102009.WAA04728@pauillac.inria.fr>
Subject: Re: Stdlib regularity
To: matias@k-bell.com
Date: Sun, 10 Oct 1999 22:09:08 +0200 (MET DST)
In-Reply-To: <37FDFA4E.456CCA68@k-bell.com> from "=?iso-8859-1?Q?Mat=EDas?= Giovannini" at Oct 8, 99 11:06:10 am
> Yes! Yes! I always begin my Caml code by writing iota, and I wish it
> were included in the standard library. It's silly simple, and imprescindible.
>
> let iota n =
> let rec aux l n =
> if n > 0 then aux (n::l) (n-1) else l
> in aux [] n
We may reuse this ``prelude'' code that slightly generalizes iota (named
range in this version of the standard library):
(*\
\subsection{Lists of consecutive integers}
\index{Lists of consecutive integers}
\begin{caml_primitive}
interval
range
\end{caml_primitive}
\begin{itemize}
\item \verb"interval n m" returns the list of all integers in
increasing order, from \verb"n" to \verb"m".
\item \verb"range n" gives the first n integers.
\end{itemize}
\*)
let interval n m =
let rec loop l m =
if n > m then l else loop (m :: l) (pred m) in
loop [] m;;
let range = interval 1;;
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:26 MET