| Marcin 'Qrczak' Kowalczyk 2005-11-04, 7:58 am |
| Followup-To: comp.lang.functional
Ulrich Hobelmann <u.hobelmann@web.de> writes:
>
> No, each iteration is only a goto. To find out the sequence type, the
> macro could start with checking the sequence type and then do one of
> maybe three different loop bodies,
Duplicating the loop body risks exponential code explosion for nested
loops, and it's only suitable for a small fixed number of sequence types.
I know that CL and Scheme have a fixed number of sequence types, but
this is not enough for my taste.
> or it could use virtual sequence accessors (is-last-element?, next)
> with the associated cost, of course.
This is what I said (the second variant). Getting the next element
through an indirect/virtual/generic call is as (in)efficient as
evaluating the body by calling a function.
> IMO the programmer should declare the sequence type, though, for
> clarity, so in that case you end up with just one fine compiled
> loop.
I agree with the *ability* to declare it (although you can't do that
in my Kogut), but I don't want to be forced to do it. I want to say
"what", not "how". I wan't a nice clean API, not separate variants of
iteration over plain lists, lazy lists, arrays, byte arrays, boolean
arrays etc., and all their combinations in case of serial or parallel
iteration.
In Kogut each sequence type provides a constructor function with a
uniform interface: taking any number of collections, and populating
the newly created collection with elements taken from them. For
example:
Array() // a new empty array
Array [10 20 30] // populate with these elements
Array someByteArray // convert a byte array to a generic array
Array arr1 arr2 // concatenate two arrays
Array arr // clone an array
Array (Fill 256 0) // initialize with 256 zeros
Array (Between "A" "Z") // initialize with capital letters
Array (Fill (10 - Size a) Null) a // right-justify a to 10 elements
Array (ReadLinesGenFrom f) // initialize with lines read from a file
and the same applies to other collection types. I can't imagine
a monomorphic interface for every combination.
--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
|