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

----- Original Message -----
From: "Ladislav Mecir" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 15, 2002 7:15 PM
Subject: [REBOL] Re: [refactoring s-c?]


> Hi Pat,
>
> thanks for looking into that. The goal of the USE and REDUCE usage is to
> create a word equal to a given word but not the same as the given word. I
> could have defined a function NONSAME as follows:
>
>     nonsame1: func [
>         {
>             create a word equal to the given word
>             but not the same as the given word
>         }
>         word [word!] {the given word}
>     ] [
>         use reduce [word] reduce [
>             'first reduce [word]
>         ]
>     ]
>
> My implementation was incorrect (as I have found out when I looked into
it).
> A correct implementation should have been as follows:
>
>     nonsame: func [
>         {
>             create a word equal to the given word
>             but not the same as the given word
>         }
>         word [word!] {the given word}
>     ] [
>         first use reduce [word] reduce [
>             reduce [word]
>         ]
>     ]
>
> Can you find my error?
>
> The implementation of the S-C? function could then have been as follows:
>
>  s-c?: func [
>         {Are word1 and word2 bound to the same context?}
>         word1 [word!]
>         word2 [word!]
>     ] [
>         found? any [
>             all [
>                 undefined? word1
>                 undefined? word2
>             ]
>             all [
>                 not undefined? word2
>                 same? word1 bind nonsame word1 word2
>             ]
>         ]
>     ]
>
> Cheers (and thanks for your question)
>     Ladislav
>
> ----- Original Message -----
> From: "pat665" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, March 13, 2002 10:43 PM
> Subject: [REBOL] [refactoring s-c?]
>
>
> Hi rebollers
>
> Again exploring Ladislav's contexts.html, I have difficulty understanding
> the s-c? function. The goal of the s-c? function is to test if two words
are
> in the same context.
>
> "Two Words WORD1 and WORD2 are bound to the same context, if the
expression
> (s-c? word1 word2) yields TRUE."
>
> Here (1) is the original version of s-c? and (2) my simplified version.
Both
> return the same result (3). Something is certainly missing in the
simplified
> version, but what ? what are the purposes of the 'use and 'reduce in the
> original version ?
>
> (1)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; s-c? function
>
>  undefined?: func [
>         {determines, if a word is undefined}
>         word [any-word!]
>     ] [
>         error? try [error? get/any :word]
>     ]
>
>  s-c?: func [
>         {Are word1 and word2 bound to the same context?}
>         word1 [word!]
>         word2 [word!]
>     ] [
>         found? any [
>             all [
>                 undefined? word1
>                 undefined? word2
>             ]
>             all [
>                 not undefined? word2
>                 same? word1 bind use reduce [word1] reduce [
>                     'first reduce [word1]
>                 ] word2
>             ]
>         ]
>     ]
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; the (over?) simplified version
>
> (2)
>  sc: func [
>         {Are word1 and word2 bound to the same context?}
>         word1 [word!]
>         word2 [word!]
>     ] [
>   print mold use reduce [word1] reduce ['first reduce [word1]]
>         found? any [
>             all [
>                 undefined? word1
>                 undefined? word2
>             ]
>             all [
>                 not undefined? word2
>                 same? word1 first bind [word1] word2
>             ]
>         ]
>     ]
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; tests
>
> (3)
>
>  >> o: make object! [a: 1 b: 2]
>  >> a: 100
>  == 100
>  >>
>  >> word1: 'a
>  == a
>  >> word2: second first o
>  == a
>  >> word3: third first o
>  == b
>
> The original s-c? gives :
>
>  >>s-c? word1 word2
>  == false
>  >>s-c? word1 word3
>  == false
>  >>s-c? word2 word3
>  == true
>
> The simplified version gives
>
>  >>sc word1 word2
>  a
>  == false
>  >>sc word1 word3
>  a
>  == false
>  >>sc word2 word3
>  a
>  == true
>
> As for the subject of this post, I was just kidding. I'am pretty sure that
> Ladislav's code do not need any refactoring.
>
> Patrick
>
>
>
____________________________________________________________________________
> __
> ifrance.com, l'email gratuit le plus complet de l'Internet !
> vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP...
> http://www.ifrance.com/_reloc/email.emailif
>
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>
>
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>

 
______________________________________________________________________________
ifrance.com, l'email gratuit le plus complet de l'Internet !
vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP...
http://www.ifrance.com/_reloc/email.emailif


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to