Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] context of a function Re:(4)

From: rebol:techscribe at: 22-Aug-2000 16:58

Hi Frank,
>> Re 1: >> You can easily determine which words are bound to the context of a function >> by retrieving the first or third block of a function. > >No, thats not possible. Example: > >> f: func [a] [a] > >> make object! [a: none insert second :f 'a]
You are taking issue with the terminilogy here, not with factual statement. I tend to think of words and instances of words. I tend to say: It is simple to determine which words are bound to the context of a function. We must do a little more work to determine whether an instance of the word a is bound to the context of the object or to the context of the function. You may prefer to use the terms symbol and word or token and word where I use word and instance. Then the problem could be formulated as: It is simple to determine which symbols are bound to the context of a function. We must do a little more to determine whether the word a is bound to the context of the object or to the context of the function. Or It is simple to determine which tokens are bound to the context of a function. We must do a little more to determine whether the word a is bound to the context of the object or to the context of the function. In any event, it is simple to determine which words (symbols or tokens) are bound to the context of a function, i.e. to generate a block that lists those words (symbols or tokens). It takes a little more effort to determine whether a specific instance of a word (or a word) is bound to a specific context.
>There is no way to find out, which of the a's is the one, which is bound >to functions context now. > >> With exception of /local all of these words are bound to the function's >> context, as soon as the function is constructed. > >Local (as a word) is, too.
Factually yes (see Brian's email and my response to him). Conceptually that is irrelevant, since the purpose of /local is to distinguish between words that are intended to be used locally, and words that are exposed globally (i.e. that receive an argument.) I think it would be very bad style to use /local and words declared after /local for any other purpose.
>> Re 2: >> You can easily bind the words in the function's first or third block to the >> function's context: >> >> >> bind fblock first second :f >> == [a ref b] > >Not possible here: > > f: func [a] []
That is why I introduced the cfunc function.
>No word example -> no way to say bind. That s why we need in for >functions.
I pointed that out in my first email in this thread, where I argued that the cfunc function would take care of that, by ensuring that there was a local word self defined, which would always be the first word in the function's body.
>> Re 3: >> You can now easily determine which values the words are associated with in >> the function's context: > >Same problem as above.
That was solved.
>> Conclusion: >> This approach only works if there is at least one word that is local to the >> function's context available at a known index in the function's body. In >> this example it was the word "a" in the first position in the function's
body.
>You could overwrite func, but I think, REBOL should support this. Its the >same as in objects.
I don't think it's one (REBOL should) versus the other (REBOL can support that now, if you want). I think it's a good idea that REBOL should support this. At the same time I think that the combination of cfunc, get-context-block and in-func permit you to already do that now, without modifying func, even though you could probably modify func, if you want to take it to that extreme.
>To serialize functions like shown above (the one with the two a's), you >need a way to find out, which of the a's are bound to functions body and >which not. I would like to use "in" for that, which would be the same >sollution as for objects.
I presented the in-func function which does just that. Regards, ;- Elan [ : - ) ] author of REBOL: THE OFFICIAL GUIDE REBOL Press: The Official Source for REBOL Books http://www.REBOLpress.com visit me at http://www.TechScribe.com