[EMAIL PROTECTED] wrote:
> 
> Hi Ladislav,
> 
> you wrote:
  ...
> >
> >Let's get to the above example, but let's use a little bit different code:
> >
> >f: func [/local a b] [ a: "" b: copy "" for i 1 6 1 [append a i append b i]
> >print a print b]
> >>> f
> >123456
> >123456
> >>> f
> >123456123456
> >123456
> >>> f
> >123456123456123456
> >123456
> >
  ...
> 
> If we were to agree with your formulation that the difference we
> observe in the function's behavior with respect to the strings
> referenced by 'a and 'b is due to
> 
> >the creation of B
> >is "dynamic" as opposed to A, where the creation is "static"
> 

I think Ladislav made the same mistake in expressing his ideas that I
did in an earlier post.  It is sloppy verbal shorthand, following a
statement such as

    a: 2

to say that "a is two".  Obviously it would be more precisely correct
to say that "a refers to the value 2".  Clearly I should not have
indulged in that kind of sloppiness, given that my effort was to point
out the need for more precise terminology.

However, it seems to me that the point Ladislav was trying to make
was that *the value to which 'a is set* is persistent, while *the
value to which 'b is set* is a newly created string.  Since 'a is set
to refer to a persistent value, successive changes to/via 'a are
changing that persistent value.  Since 'b is set to refer to a newly
created value each time, changes made to/via 'b do not accumulate
in the same way.

>
> then we would be very surprised by the following demonstration,
> wouldn't we?
> 
> f: func [/local a b] [
>   a: ""
>   b: copy ""
>   for i 1 6 1 [
>     append a i append b i
>   ]
>   print a print b
>   insert pick second :f 5 copy/part second second :f 6
> ]
> 
> The line in which 'b was created wasn't changed. Most dramatically, it
> continues to be the exact same line you commented on as
> 
> >the creation of B
> >is "dynamic" as opposed to A, where the creation is "static"
> 

The second line of the body of 'f still creates a new string each time.
However, it is creating that string by duplicating a persistent string,
(the fifth element of the body of 'f).  Since the last line added to
'f simply modifies the string being duplicated, it's a bit unfair to
claim that "the line in which 'b was created wasn't changed".

In fact, the "line in which 'b was created" was INITIALLY the same as
Ladislav's example, but the added line at the end MODIFIES the "line
in which 'b was created" at every execution.  To use a simplified but
equivalent example:

    >> f: func [/local a b][
    [    a: ""
    [    b: copy ""
    [    append a "X"
    [    append b "Y"
    [    print [a b]
    [    insert pick second :f 5 copy second second :f
    [    ]
    >> f
    X Y
    == ""
    >> f
    XX XY
    == "X"
    >> f
    XXX XXXY
    == "XXX"
    >> source f
    f: func [/local a b][
        a: "XXX"
        b: copy "XXXXXX"
        append a "X"
        append b "Y"
        print [a b]
        insert pick second :f 5 copy second second :f
    ]
    >>

Looks like "the line in which 'b was created" has been changed!

Let's play fair here!  If I define a function as:

    >> f: func [] [
    [    print "now you see it,"
    [    print "now you don't!"
    [    ]
    >> f
    now you see it,
    now you don't!
    >> f
    now you see it,
    now you don't!

and then modify it as:

    >> f: func [] [
    [    print "now you see it,"
    [    print "now you don't!"
    [    clear second :f
    [    ]
    >> f
    now you see it,
    now you don't!
    == []
    >> f
    >> f
    >>

it's hardly fair to claim that since the first two lines are the same
that I should continue to expect the same behavior from these two
functions!

-jn-

Reply via email to