uppercase
[1/5] from: louisaturk:eudoramail at: 27-May-2002 20:50
Hi rebols,
>> x: "hello"
== "hello"
>> y: uppercase x
== "HELLO"
>> x
== "HELLO" <====<<<< Why is x now uppercase?
This is really unexpected behavior! Is this a bug?
Is it like this in the new version of rebol (I haven't upgraded yet)?
Louis
[2/5] from: chalz:earthlink at: 28-May-2002 1:16
That is rather odd. The function, I do not feel, should actually perform an
operation on the argument being passed. At least, not in general. Same
happens with 'lowercase'.
Well, it answers the question I recall seeing about capitalizing:
[3/5] from: brett:codeconscious at: 28-May-2002 14:45
Hi,
> >> x: "hello"
> == "hello"
<<quoted lines omitted: 3>>
> == "HELLO" <====<<<< Why is x now uppercase?
> This is really unexpected behavior! Is this a bug?
No it is not a bug. It is actually a nice flexible design.
There are two things at work here.
(1)--------------
Look at these two lines of code:
a-symbol-for-the-string: "The String"
also-a-symbol-for-the-same-string: a-symbol-for-the-string
The word A-SYMBOL-FOR-THE-STRING is set to the string (reference to the
string).
The word ALSO-A-SYMBOL-FOR-THE-SAME-STRING is set to the value (after
evaluation) of the word A-SYMBOL-FOR-THE-STRING. Since this value is a
string (reference to the string), both word refer/set/point to the
exact same string.
BTW, The same behaviour occurs if instead of a STRING! you used a BLOCK!
- it happens for all series types.
(2)---------------
UPPERCASE, LOWERCASE, SORT, REVERSE modify the string that they are
given. It is *not* that they take a string, process it and return the
processed results. Instead, they take a string, modify that string, and
return a reference to that *same* string so that possibly another
function can use it as an argument.
For example:
>> x: "hello"
== "hello"
>> uppercase x
== "HELLO"
>> x
== "HELLO"
>> x: "hello"
== "hello"
>> sort uppercase x
== "EHLLO"
>> x
== "EHLLO"
The reference to the string that is returned in some cases is also
modified from the original. It is a reference to the same string but it
points to a different character in that string. In the case of REVERSE
for example, the index position points to the character after the
characters that were reversed:
>> x: "hello"
== "hello"
>> y: reverse/part x 3
== "lo"
>> x
== "lehlo"
>> same? x head y
== true
Now I said it was a flexible design. The reason is this. Imagine that
you have a huge string.
x: {An absolutely huge string...}
For UPPERCASE to do what you expected it would have to copy the string
it was given. So that just doing...
uppercase x
...would mean that you would have two huge strings in memory. Do you
have enough memory in your computer to complete the task? The designer
of these functions decided he could not answer this question so instead
leaves the choice to you. If you decide that you must not touch the
original string then you should make your own copy of it. Like this
>> x: "hello"
== "hello"
>> y: uppercase copy x
== "HELLO"
>> x
== "hello"
>> y
== "HELLO"
I hope that clears it up a bit.
Brett.
[4/5] from: anton:lexicon at: 28-May-2002 15:41
No, I don't think it is a bug.
It is just like replace.
Just work on a copy of x:
y: uppercase copy x
And this is the same in the latest view beta I'm running.
Anton.
[5/5] from: carl:cybercraft at: 28-May-2002 18:36
On 28-May-02, Charles wrote:
> That is rather odd. The function, I do not feel, should actually
> perform an operation on the argument being passed. At least, not in
> general. Same happens with 'lowercase'.
> Well, it answers the question I recall seeing about capitalizing:
>>> uppercase/part x 1
> ;)
It's rather subjective, I think, and perhaps based on us not being
used to "uppercase" as a verb. 'clear, 'replace 'trim and other words
work on the argument, so why not 'uppercase? It's also more useful I
think, as instead of this...
x: uppercase x
we can use...
uppercase x
>> Hi rebols,
>>>> x: "hello"
<<quoted lines omitted: 4>>
>> == "HELLO" <====<<<< Why is x now uppercase?
>> This is really unexpected behavior! Is this a bug?
I'm pretty sure it isn't. But to get around your above problem, just
use 'copy. ie...
>> x: "hello"
== "hello"
>> y: uppercase copy x
== "HELLO"
>> x
== "hello"
>> y
== "HELLO"
>> Is it like this in the new version of rebol (I haven't upgraded
>> yet)?
>> Louis
--
Carl Read
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted