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.

Reply via email to