[Kc] response to apo6 transfinite semantics challenge

david nicol whatever at davidnicol.com
Wed Mar 12 04:07:01 CST 2003


Larry Wall writes:



> However, if you access the last element using the length of the array,
> it may try to flatten, and fail:
> 
>     my @flat = (1..Inf, 1..10);
>     $last = @flat[@flat - 1];   # Kaboom!
> 
> Still, we should be able to detect the attempt to flatten an infinite
> list and give a better diagnostic than Perl 5's "Out of memory".
> Either that, or someone should just up and figure out how to subscript
> arrays using transfinite numbers.

We've got Inf, right?  So we know that scalar(()=(1..Inf) is Inf.

Inf - 1 is still Inf.

The only thing we need to define is what @arr[Inf] means.

It seems clear from the previous several paragraphs that Larry wants
someone to suggest, as part of the transfinite package, that

	@arr[Inf]

can be defined as sugar for

	{
	  my $_ = pop @arr;
	  push @arr, $_;
	  $_;
	 }

And this might even just be a special case that perl6 array-FETCH is
supposed to know about. (or create a LAST tie operator.)


The range specs that know their own length without flattening (see
a few paragraphs prev. in apo6) and counting would know if they are Inf.





-- 
David Nicol, independent consultant and contractor
perl -Mcoroutine0 -e'$c=new coroutine0 VARS=>[],BODY=>q"YIELD 74;
YIELD 65;YIELD 80;YIELD 72; YIELD 10;";print chr$_ while$_=&$c;'





More information about the kc mailing list