[REBOL] Re: [RWEBOL] HOF and system exploration
From: jan:skibinski:sympatico:ca at: 26-Oct-2002 15:30
Hi Gabriele and Ladislav:
>From Gabriele:
>
> You didn't seem to have tried all the possibilities. :-) Why don't
> you try with:
>
> lado :sine
> lado :sine 90
>
> and contrast it with:
>
> do :sine
> do :sine 90
..and from Ladislav:
> try this:
> do :+ 1 2
> lado :+ 1 2
==========================================
But
lado + 1 2
== 3
or
plus: :+
lado plus 1 2
== 3
or
sin: :sine
lado sin 90
== 1
===========================================
Involved in our tests of 'do and 'lado is one extra complexity layer that
involves silent convertion of command line into block of expressions,
I think.
So why don't we simplify the tests by supplying the 'do with
a block of expression(s) instead?
>> e1: [+ 1 2]
>> do e1
== 3
>> lado e1
== 3
So far so good! Now, let us substitute "+" by ":+":
>> e2: [:+ 1 2]
== [:+ 1 2]
>> do e2
== 2
>> lado e2
== 2
Neither 'do nor 'lado recognized that the intend here was to get
the value of '+ and then to apply it to the rest of the expression.
My interpretation of this is that both evaluate ":+" but do not
bind it to anything, and then continue evaluating first 1 then 2.
Let's see:
>> e3: do/next e2
== [op [1 2]]
>> e3/2: 1
== [op 1]
>> append e3 2
== [op 1 2]
Now let's repeat the test using this precalculated 'op:
>> do e3
== 3
>> lado e3
== 3
We can of course make a variation of the functional 'similar,
which replaces all 'get-words by 'words and then produces
a version of 'lado that works with expressions containing :+, etc.
Here is a quick example (with constraint on the arg type):
lado2: func [
arg [block!]
/local t
][
t: map :no-colon arg
native t]
>> lado2 [:+ 1 2]
== 3
But that's beside the point.
All the above tests could be run using the string versions, rather
than the block versions of the example expressions, such
as ":+ 1 2". The outcome would be exatly the same as for
the previous tests.
To summarize: I do not think there is a problem with the 'similar
functional, nor with the functions it generates - and that includes
clones
of the 'do function. But there is some extra functionality of
'do which interacts with the toplevel environment and which confuses
the issue. I am refering to the core manual, which describes in passing
how the command lines are being embedded in a block before
being processed by 'do.
Best wishes,
Jan