Re: variables in 'let rec'

From: John Max Skaller (skaller@maxtal.com.au)
Date: Thu Mar 30 2000 - 11:52:37 MET DST

  • Next message: John Max Skaller: "Re: to have labels or not"

    Sven LUTHER wrote:
    >
    > On Tue, Mar 28, 2000 at 11:03:36AM +1000, Max Skaller wrote:
    > > Damien Doligez wrote:
    > > >
    > > > >From: Max Skaller <maxs@in.ot.com.au>
    > > > >
    > > > >Alternatively, you can just use
    > > > >
    > > > > let rec x' () = ...
    > > > > and ...
    > > > > let x = x()
    > > > >
    > > > >in lieu of what you really wanted: (that is,
    > > > >there is a workaround).
    > > >
    > > > But that doesn't work for "let rec x = 1 :: x", which is the most
    > > > interesting feature of O'Caml's recursive value definitions.
    > >
    > > It doesn't?
    > >
    > > let rec x'() = 1 :: x()'
    > > let x = x'()
    >
    > FYI :
    >
    > bash-2.03$ ocaml
    > Objective Caml version 2.99 (99/12/08)
    >
    > # let rec x = 1 :: x ;;
    > val x : int list =
    > [1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
    > ...]

    Ah! I withdraw my last comment: the list is constructed as instructed,
    resulting in a circular list. The printer routines recognizes this,
    or at least is smart enough to apply a printing limit.

    _Traversing_ the list may take infinite time, but examining
    the first n elements will not. (And the construction is
    constant time :-)

    -- 
    John (Max) Skaller, mailto:skaller@maxtal.com.au
    10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
    checkout Vyper http://Vyper.sourceforge.net
    download Interscript http://Interscript.sourceforge.net
    



    This archive was generated by hypermail 2b29 : Sun Apr 02 2000 - 23:34:17 MET DST