[REBOL] Re: [refactoring s-c?]
From: rebol665:ifrance at: 16-Mar-2002 18:24
Hi Ladislav,
I am even more confused, but I like that!
I can play the luke-who-wants-to-be-a-jedi part, master Yoda.
1. Assuming that nonsame is correct, I have tested that :
a: 100
word1: nonsame 'a
>> s-c? 'a 'word1
== true
I was puzzled because I thought that use will create a new context and
return something bound to this context. I had found an interesting example
of that in the escribe archives :
a: 1
block: [a]
use [a] [a: 2 append tail block [a]]
>> block
== [a a]
>> s-c? first block second block
== false
Fortunately I realized my mistake and that the correct testing was :
>> s-c? 'a word1
== false
That was confirmed by
>> s-c? 'a nonsame 'a
== false
Assertion 1 : nonsame returns a word bound to another context.
Assertion 2 : this context is created by use.
Assertion 3 : nonsame returns a word with the same spelling.
>> mold word1
== "a"
>> mold 'a
== "a"
I am aware that assertion 1 and assertion 3 are certainly bound because it
is not possible to have two words with the same spelling in the same
context.
2. From (1) I have learned that use was required to create a new word with
the same spelling but different. As for comparing nonsame1 and nonsame, I
have learned nothing. As far as I can tell they are equivalent :
>> word2: nonsame1 'a
== a
>> s-c? 'a word2
== false
3. Why reduce ? I have still no idea, but I can try removing it and see what
happens.
ns: func [
word [word!] {the given word}
][
use [word][word]
]
>> ns 'a
** Script Error: word has no value
** Where: ns
** Near: word
Definitively wrong
ns: func [
word [word!] {the given word}
][
use [word] reduce [word]
]
>> ns 'a
== 100
Returns a value. It is not good.
ns: func [
word [word!] {the given word}
][
use [word] reduce ['first reduce [word]]
]
>> ns 'a
== a
Looks better. first is used to extract a word rather than a value. An extra
block is needed to be the body that use requires. However this is not good
because :
>> same? 'a ns 'a
== true
Assertion 4 : I am exhausted !
4. As far as I can tell now, I am not able to explain why nonsame is better
than nonsame1. All my experiments have fail to prove any of :
- nonsame1 and nonsame do not return always the same result
- nonsame1 has an undesired side-effect
- nonsame1 rises an error
5. Epilogue
Learning that I know nothing is indeed a valuable lesson. Knowing that is
certainly better than pretending to know something that I don't. I don't
know if I am ready for understanding the truth. It is not for the apprentice
to decide. I have spent half my day with all these trials and must return
now to a normal life ! Hoping for the best
Patrick