"Jeremy Howard" <[EMAIL PROTECTED]> writes:

> Damian Conway wrote:

[...]

> > Personally, I intend only to update the RFC to include the *possibility*
> > of (..$x) and (..). I'm reasonably sure Larry will kill the whole thing
> > -- I think I might too, were I in his place ;-)
> >
> Now don't encourage its death already! Still, I'm glad you're prepared to
> keep it open.

Please somebody post some sane semantics for lazy "generalised lists"
with any (computable) countable order type.  That way lies madness
(and no applications that I can think of).

> 
> > Rather than continue to argue the details, why don't people post some
> > examples of code where they feel these lazy lists might be useful, and
> > let's see if there aren't already good alternatives.
> >
> OK, you're on. But infinite lists (can I say that?... 'semi-finite' is a bit
> weird) are one part of a bigger picture, so let me show you some code that
> also incorporates higher-order functions, and an extension to Christian
> Soeller's upcoming RFC on notation for slicing.
> 
>   @matrix = (1,3,4,2,6,7); # actually a flattened version of
> [[1,3,4],[2,6,7]]
>   @column1of3 = (1:3:); # Creates an infinite list (1,4,7,...)
>   print sum(@matrix[@column1of3]); # Prints 3
>   @matrix2 = readReallyBig3ColumnMatrixFromSomewhere();
>   $column1Sum = sum(@matrix2[@column1of3]); # Handy, no need to redefine our
> slice!

This is a straightforward "forwards list"; it has the order type of
(1..), not of (..-1).

[...]

> Another win is in evaluation of lists constructed by generator functions:
>   # ($start: f(__): $end) == ($start, f($start), f(f($start)), ...)
>   @powersOf2 = (1:__*2:); # (1, 2, 4, 8, ...)
>   @first10PowersOf2 = @powersOf2[0..9]; # Calculates 1st 10 powers of 2
>   # ...interesting manipulation of @first10PowersOf2...
>   @first20PowersOf2 = @powersOf2[0..19] # Calculates 2nd 10 powers of 2 (1st
> 10 are already computed!)

This is another straightforward "forwards list"; it has the order type 
of (1..), not of (..-1).

Please post examples of places where "generalised lists" of other
order types are useful.

> The real difference between an infinite list and a function with a domain of
> the integers (other than notation) is that an infinite list is a guarantee
> of stability. If we've already calculated @powersOf2[9], we don't have to do
> it again when we next want it. The same is not true of 2^__, since perl
> can't know that it returns the same result for every evaluation (for
> instance, what if it was <>^__ ?)
> 
> You could argue that we could achieve the same with an attribute of a sub,
> such as 'stable'. This would guarantee that this function returns the same
> result each time it's called with the same arguments. Then perl would be
> smart enough to cache the result of calls to this sub to avoid recalculating
> it again later. Personally, however, I find this approach less intuitive.

MJD has a perl5 package which does memoization; this is exactly what
you want.

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | [EMAIL PROTECTED]
Compugen Ltd.          |Tel: +972-2-6795059 (Jerusalem) \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658514 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels

Reply via email to