Is it a list ?

Chris Pressey cpressey@REDACTED
Thu Jul 10 20:53:51 CEST 2003


On Thu, 10 Jul 2003 20:19:25 +0200
Joachim Durchholz <joachim.durchholz@REDACTED> wrote:

> > Or asked differently, is there a legitimate use for ill-formed
> > lists?

Section 2.6.2 of the "Erlang Extensions since 4.4" document gives one
such use:

  2.6.2 Infinite Lists

  The idea is to write something like:

  -module(lazy).
  -export([ints_from/1]).
  ints_from(N) ->
      fun() ->
              [N|ints_from(N+1)]
      end.

  Then we can proceed as follows:

  24> XX = lazy:ints_from(1).
  #Fun<lazy>
  25> XX().
  [1|#Fun<lazy>]
  26> hd(XX()).
  1
  27> Y = tl(XX()).
  #Fun<lazy>
  28> hd(Y()).
  2

  etc. - this is an example of "lazy embedding"

-Chris



More information about the erlang-questions mailing list