Hi Volker and Joel,

1) I didn't want to criticize the ineffectivity of the algorithm. I would
rather say, that what matters to me may be a "naturality" of the algorithm.

2) Joel's examples as well as Volker's look to me as "top down writing
style", while my attempt uses a "bottom up" approach. I am convinced, that
the "bottom up style" can be used to improve the readability.

3) Volker is right, that the introduction of iteration using FOREACH
simplifies the code. For the comparison purposes, here is an iterative
version of FLAT-APPEND:

    flat-append: func [
        series [series! port!]
        value [any-type!]
    ] [
        either block? get/any 'value [
            foreach element value [
                flat-append :series get/any 'element
            ]
        ] [
            insert/only tail :series get/any 'value
        ]
        :series
    ]

It is advisable to use the iteration, where it looks more natural/readable
(at least in Rebol).

4) I noticed a paradox: the most effective way of assembling blocks is to
use APPEND (or INSERT TAIL), but we do not have it as a native. Moreover,
the APPEND function should be enhanced to allow the same types of
arguments/refinements as INSERT does. (sending as an enhancement request to
feedback too).

append: function [
    {Appends a value to the tail of a series and returns the series.}
    [catch]
    series [series! port! bitset!] "Series at point to insert"
    value [any-type!] "The value to insert"
    /part "Limits to a given length or position."
    range [number! series! port!]
    /only "Inserts a series as a series."
    /dup "Duplicates the insert a specified number of times."
    count [number!]
] [path block] [
    path: to path! [insert]
    block: reduce [:path 'tail :series]
    insert/only tail block get/any 'value
    if part [
        insert tail path 'part
        insert/only tail block :range
    ]
    if only [
        insert tail path 'only
        insert tail block :range
    ]
    if dup [
        insert tail path 'dup
        insert tail block :count
    ]
    throw-on-error block
    :series
]

The CHANGE function should be enhanced too, to allow ANY-TYPE! VALUE
argument.

-L

----- Original Message -----
From: "Joel Neely"

Hi, Volker and Ladislav,

Volker Nitsch wrote:
>
> aha! hmm2: all this inserting at front, and recursion? (coding)
>
...
>
> obviously you coded for example, not performance ;)
>

Absolutely!  I'm under no illusion that the sample code offered
was the best algorithm/approach for the problem.  That the first
version was just leftovers from some benchmarking I had done a
while back -- it was just the first fragment of code that came
to hand that had some deeply-nested expressions.

I assure one and all that I do NOT recommend constructing
blocks from right to left!

Of course, that sentence betrays that my native/habitual language
is Indo-European-based (reading left-to-right) rather than Hebrew
or Arabic (reading right-to-left) or ancient Greek (when written
in boustrophedon).

-jn-

--
; Joel Neely                             joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]



-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to