Hello, there is a weakness in the Rebol block implementation,
because Append is much faster than Insert Head. The performance of
Insert Head can be improved to be equal, IMHO.
About the use of ILs: it is just a toy, but usable, although I
cannot approve such use as Mold A, where A is an IL, because it
may be a very stack-demanding operation for Rebol and, moreover,
it is in contradiction with the following disclaimer: I am
underlining, that the manipulation has to be indirect, ie. through
defined primitives, otherwise no fitness for any purpose can be
claimed. If you want to convert ILs to strings, here is a sample
code (working mainly for the simplest possible case, because I
didn't implement an enlargement of the Rebol type-checking
mechanism to recognize ILs):
il-mold: func [il /local result] [
result: copy "il-make ["
while [not il-empty? il] [
append result form il-first il
il: il-next il
]
append result "]"
]
About the unfairness of the approach: I just wanted to point out
some differences. You can even see the programmer's overhead:
instead of Prepend I A she shall use A: Prepend I A.
Moreover, this is not the only possible implementation of
immutable series. The implementation depends highly on the set of
the operations that have to be elementary ie. not having the
execution time dependent on the size of the of series.
Ladislav
>
> Hi,
>
> Gabriele writes:
>
> >Hello [EMAIL PROTECTED]!
> >
> >On 11-Gen-00, you wrote:
> >
> > l>>> st/start a: empty-il for i 1 20000 1 [a: prepend i a]
> > l>>> st/stop
> > l> == 0:00:03
> > l>>> st/start a: copy [] for i 1 20000 1 [insert a i] st/stop
> > l> == 0:01:36
> >
> >You're not fair, Ladislav!
> >
> >>> t: now/time a: make list! [] for i 1 2000 1 [insert a i]
(now/time - t)
> >== 0:00:02
> >>> t: now/time a: make block! [] for i 1 2000 1 [insert a i]
(now/time - t)
> >== 0:00:13
> >
> >Trying to test with your immutable lists made REBOL crash with
a
> >guru on my Amiga (this is the first time I get a guru from
> >REBOL!); I'll have to spend some time on this...
> >
> >Regards,
> > Gabriele.
>
> I crashed too, in windows, trying to do PRINT MOLD A. Still, it
seems to
> work otherwise.
>
> >> tic a: empty-il for i 1 20000 1 [a: prepend i a] toc
> elapsed time: 0:00:01
> >> a/what
> == 20000
> >> a/nxt/what
> == 19999
> >> a/nxt/nxt/what
> == 19998
> >> b: a loop 19000 [b: b/nxt] b/what
> == 1000
>
> That's fun. Is it fast?
>
> >> tic loop 10 [b: a loop 19000 [b: b/nxt] b/what] toc
> elapsed time: 0:00:09
>
> Oooh, that's kinda slow.
>
> >> a: copy [] tic for i 1 20000 1 [insert a i] toc
> elapsed time: 0:00:51
>
> That was slow all right, but:
>
> >> tic loop 1000000 [pick a 19000] toc
> elapsed time: 0:00:03
>
> is not too shabby.
>
>
> Gabriele points out that inserting at the head with lists is
much faster.
> Also appending to blocks is much faster than inserting at the
head. The
> longer the blocks get, the longer the insertion takes. Appending
takes
> longer too, but the performance hit isn't nearly so bad.
>
> >> a: copy [] tic loop 10 [for i 1 1000 1 [insert a i] toc]
> elapsed time: 0:00
> elapsed time: 0:00:01
> elapsed time: 0:00:01
> elapsed time: 0:00:02
> elapsed time: 0:00:03
> elapsed time: 0:00:05
> elapsed time: 0:00:07
> elapsed time: 0:00:09
> elapsed time: 0:00:11
> elapsed time: 0:00:13
> >> a: copy [] tic loop 10 [for i 1 1000 1 [append a i] toc]
> elapsed time: 0:00
> elapsed time: 0:00
> elapsed time: 0:00
> elapsed time: 0:00
> elapsed time: 0:00
> elapsed time: 0:00
> elapsed time: 0:00:01
> elapsed time: 0:00:01
> elapsed time: 0:00:01
> elapsed time: 0:00:01
>
> See you,
> Eric
>
>
>