Hi Ladislav, 1. first 'first
If I understand nonsame1 is equivalent to nonsame except if called with the word 'first. <<yoda>> same? 'first nonsame1 'first ** Script Error: first has no value <<L>> So I have tried to find out the part of nonsame1 that breaks ... In the following line from nonsame1, I see two parts : use reduce [word] reduce ['first reduce [word]] or use <part 1> <part 2> <part 1> being a block of words, here a block with only one word. <part 2> being a block to evaluate. Evaluation returning the given word. A little test shows that <part 1> is correct. >> myword: 'first == first >> reduce [myword] == [first] Therefore I concentrate myself on <part 2>. To emulate <part 2> I create this little function test: func [x [word!]][do reduce ['first reduce [x]]] However I was desappointed with the result. >> test myword == first No error, so neither <part 1> or <part 2> is responsible for the error. It is only when they are bind together by use, that an error rises. I think also there is nothing wrong with 'first by itself. To clear that, I have made the following test where 'first is replaced by 'second. >> test2: func [word [word!]][use reduce [word] reduce ['second reduce [word]]] >> test2 'second ** Script Error: second has no value Bingo ! let's try to remove first ... >> test2: func [word [word!]][use reduce [word] reduce [reduce [word]]] >> test2 'first == [first] It is almost ok, except that a block is returned instead of a word. And it was indeed the purpose of using 'first to give us a word. A part that it returns a block, test2 give us the right thing : a word with the same spelling but not the same word. >> first test2 'first == first Here we can get the "new" first with the same spelling. >> same? 'first first test2 'first == false And it is not the same as the global first. From that it is easy to build test3 which is indeed nonsame : >> test3: func [word [word!]][first use reduce [word] reduce [reduce [word]]] >> test3 'first == first >> same? 'first test3 'first == false 2. second reduce Let's play again with my simplification of use : use <part 1> <part 2> where <part 1> is a block including one word <part 2> is a block returning that word Why can't we simply write : test4: func [x [word!]][use [x][x]] This is an answer >> use [x][x] ** Script Error: x has no value ** Where: do-boot ** Near: x The x in part 2 exists but have never been set. It has no value to return. In fact, we don't want the value of x but the word associated. May be this could work. test4: func [x [word!]][use [x]['x]] >> test4 'first == x Nope, 'x is taken litteraly here. test4: func [x [word!]][use [x][compose [('x)]]] >> test4 'first == [x] test4: func [x [word!]][use reduce [x][compose [('x)]]] >> test 'first == [first [first]] Yeah, another puzzle: one in -> two out. However it is first that comes out. So I think I understand the first reduce. Let's replace compose by reduce too. test4: func [x [word!]][use reduce [x][reduce [x]]] >> test4 'first == [first] Not bad ! but is it the real one ? >> same? 'first first test4 'first == true No luck again. Indeed it says something. Since we get the global 'first, it means that the use did not work at all. This one is a bit tricky test5: func [x [word!]][use [first][reduce [x]]] >> test5 'first == [first] >> same? 'first test5 'first == false It works, however it works only with 'first. It shows anyway that only <part 2> needs to be taken care of. Let's try to see what is wrong in that <part 2>. test6: func [x [word!]][use reduce [x][print reduce [x]]] >> test6 'first ** Script Error: first expected series argument of type: series pair event money date object port time tuple any-function library struct event ** Where: test6 ** Near: first It seems that x is evaluated again. To prevent evaluation, it can be put in an extra block. test6: func [x [word!]][use reduce [x][print [reduce [x]]]] >> test6 'first first As we know that print reduces its argument, all we have to do is to replace print by reduce. test7: func [x [word!]][use reduce [x][reduce [reduce [x]]]] >> test7 'first == [[first]] And yet there is an external block to get rid of. test8: func [x [word!]][use reduce [x] reduce [reduce [x]]] >> test8 'first == [first] >> same? 'first test8 'first == false And finally from what we learned from (1.). test9: func [x [word!]][first use reduce [x] reduce [reduce [x]]] >> test9 'first == first >> same? 'first test9 'first == false Which is not a surprise because test9 is nonsame. 3. third contexts.html I was very proud to see my name in the acknowledgements part. I show it to everybody in the house except my cat. 4. fourth unbound I noticed the replacement of error? by any-type? I will look into later, because I have very few little grey cells available at the moment. Patrick ----- Original Message ----- From: "Ladislav Mecir" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, March 17, 2002 8:44 AM Subject: [REBOL] Re: [refactoring s-c?] > Hi Pat, > > you are doing well, don't give up (use the source, Luke...), your mail is > nice. > > <<Pat>> > > ...snip... > > 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. > > ...snip... > > 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 : > > <</Pat>> > > NONSAME1 and NONSAME look so much equivalent, that it confused even me. The > only difference is the usage of 'first. That is the source of the trouble in > NONSAME1: > > same? 'first nonsame1 'first > ** Script Error: first has no value > ** Where: nonsame1 > ** Near: first [first] > > If we try this for NONSAME, we will get: > > same? 'first nonsame 'first > == false > > <<Pat>> > > ...snip... > > 3. Why reduce ? I have still no idea, > > ...snip... > > <</Pat>> > > Just in case you need it, here is the reason for REDUCE: > > word: 'a > block1: [word] > block2: reduce [word] > block3: reduce [[word]] > block4: reduce [reduce [word]] > > <<Pat>> > > ...snip... > > 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 > > <</Pat>> > > Nice epilogue :-) My feelings are similar, because my implementation of > S-C?, although pretending to be correct, was in fact incorrect. Hope the > trial and error didn't exhaust you too much. Now it should be clearer, but > feel free to ask, if anything remains unclear. > > Best regards > L > > P.S. The newest version of [Contexts] is at: > http://www.rebolforces.com/~ladislav/contexts.html > > P.P.S. How do you like the change in the UNBOUND? function? > > > -- > 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.