Hi Elan,

I've read your 1400+ line refutation of Joel's explanation of a function. I
agree with much of what you say, but there is one point I don't think is
quite right:

>2.3 Conclusion:
>2.3.1 An empty literal string does not reference "the empty string" because
>a string! value does not have the capability to reference something. That
>capability is reserved for values of type word!

(I think Joel may have used the phrase "the empty string" as a concept rather
than meaning "the unique empty string in the example".)

You "prove" this with the following demonstration:

>2.2 Each of the two literal strings is an independent entity. Since you
>speak of "the empty string" and you say " as is the fifth element", your
>formulation suggests that the two literal strings are identical, since they
>are both references to "the empty string". If they are identical, the
>function same? should return true. However, same? returns false:
>
>>> same? "" ""
>== false

In the case of the "the two literal strings" in the function F being
described it's true, and it's true with your illustration

>>> same? "" ""
>== false

In this latter illustration both literal strings are independent entities,
because REBOL creates both of them when it parses the string {same? "" ""}
typed in at the console. That still is no guarantee that all "literal
strings" are mutually independent entities.

What about this case:

>> a: [""]
== [""]
>> insert a first a
== [""]
>> a
== ["" ""]
>> same? first a second a
== true

The block referenced by (bound to) 'a now contains two string values, both of
which reference the same empty string.

This is one of the major points that Joel was trying to make in his series
essay, and one that deserves careful attention. Even series values that look
literal (that are not directly bound to a word) have a relationship of
reference to the underlying data which they represent.


Another point where I think you go slightly wrong is further down:

>>
>>The subtle point over which so many of us have tripped (judging by
>>the discussions on the mailing list) is that the the adjacent
>>quotation marks in the text entered to define 'trick serve simply
>>as the INITIAL VALUE of the second element of 'trick, and that
>>subsequent modifications (via any reference) to that second element
>>will persist as long as 'trick does.  That is the only point where
>>the concept of "global" appears, as far as I can tell.  Values are
>>not subject to garbage collection as long as there is any reference
>>(or chain of references) to them from the global context.  "Local"
>>doesn't enter into it at all.
>
>Wrong.
>
>>> false-abstraction-2: [append ""  "X" ]
>== [append "" "X"]
>>> do false-abstraction-2
>== "X"
>>> do false-abstraction-2
>== "XX"
>>> do false-abstraction-2
>== "XXX"
>>> do false-abstraction-2
>== "XXXX"
>>> do false-abstraction-2
>== "XXXXX"
>>> false-abstraction-2
>== [append "XXXXX" "X"]
>
>Here the literal string in false-abstraction-2 was modified, even though it
>wasn't being referenced by anything global.

It's true that much of what Joel said about contexts being destroyed and
local values being thereafter subject to garbage collection was mistaken.
(BTW, I've noticed that in 2.2 the behavior of local values assigned to words
local to a function is more predictable now.)

Still, I think that the important point Joel makes here is basically right.
Notice he said a "chain of references". For example, in your example the ""
in:

>> false-abstraction-2: [append ""  "X" ]

does serve "as the initial value" of the second element of the block
referenced by 'false-abstraction-2. That's because REBOL created a string
based on its parsing of the characters "" in the string
{false-abstraction-2: [append ""  "X" ]} , which was typed in at the console.
Thereafter the second element of the block serves as a reference to the data
underlying that value. The value persists, and the data to which it refers
persists (in the sense that the garbage collector doesn't gobble it up),
because it's contained in a block referred to by a word. That is indeed a
"chain of references".

I don't even think it's quite right to call the second element of the block
referenced by 'false-abstraction-2 a literal string. I think you could say it
was initialized from a literal string, but as it exists within the block
itself, it is a string value, no different in quality from one directly
referenced by a word.


In conclusion, here's a puzzle, easily solved: how did I make this function?

>> source f
f: func [x /local a b][a: "" b: copy "" append a x print b]
>> f "I'm a geek"

>> f ", not!"
I'm a geek
>> f " OK?"
I'm a geek, not!

See you,
Eric

Reply via email to