[Omake] lazy values in arrays?

Erick Tryzelaar erickt at dslextreme.com
Mon Jan 29 01:45:51 PST 2007


Erick Tryzelaar wrote:
> Erick Tryzelaar wrote:
>> Boy I'm chatty today :)
>>
>> Is there any way to store a lazy value in an array? The obvious route 
>> doesn't work: 

Last one for the night :) I got a question about working with lazy 
arrays / forcing a lazy expression. Say I wanted to map over a lazy 
array. With normal arrays, something like this:

% x[] =
% y = $(array $x, 4)

evaluates to:

- : <array
       "4" : Sequence>

A lazy expression:

% z = $`(array $x, 4)

evaluates to:

- : $(apply global.array $(apply global.x) "4" : Sequence)

This is all fine up until you try to map over the lazy expression. With 
normal arrays, since "x" is empty, it doesn't affect the output of map:

% foo(a) =
foo>      foo(a) =
foo>         printvln($a)
% y.map($(foo))
"4" : Sequence

But mapping over "z" doesn't collapse the lazy expression, and returns 
another array:

% z.map($(foo))
class Object Sequence Array
   f = <fun 1>
   object-length = <fun 0>
   object-map = <fun 1>
   object-mem = <fun 1>
   length = <fun 0>
   foreach = <fun 2>
   map = <fun 1>
   nth = <fun 1>
   $builtin = $(apply global.array $(apply global.x) "4" : Sequence)
   rev = <fun 0>
   value = <array>
              : Array
   object-find = <fun 1>
   object-add = <fun 2>
   object-foreach = <fun 3>

and since there's no "force" function to evaluate the lazy expression, 
I'm not sure how to extract the data via the array.map.

There is a workaround though. The global "foreach" function does work, 
so I can use that in the meantime.

-e


More information about the Omake mailing list