[REBOL] Re(2): Improved SOURCE function
From: arolls:bigpond:au at: 6-May-2001 19:14
Larry, you wrote:
> Well, that is exactly what SRC does. The only difference is that I kept it
> with a separate name. I think it confusing to patch over with the
> same name,
> because it leads to people producing output which differs although
> apparently using the same function.
I disagree a little, here.
You are extending source's abilities, making it
backwards compatible. (Unless people are writing
code that relies on source to fail.)
Before, no one would try to use a path with source.
Now they can.
The only place people can be confused is in explanatory
emails which they might not be able to reproduce in their
For me, the clarity gained by using the word 'source is
stronger than the effort for the user in remembering
another word, 'src.
DocKimbel is confidant enough about his patch to call it
'help. I think you should be too.
Perhaps you can make 'src a code contribution to Rebol Tech?
Then it may be incorporated into a future rebol.
> SOURCE is just a small REBOL mezzanine function, it is not defined in any
> special context. Try
> source source
> So I could have, and you may, if you like, just rename SRC to SOURCE which
> will redefine the global word. No special considerations of
> object contexts
> involved. But everytime you post an example using it, you will have to
> explain that it is a special SOURCE function.
> There is a slightly updated version on my rebsite:
> > I just can't remember how to refer to original word in systeme.
> > I am having a look around... anyone?
> Not sure what you mean there. Maybe something like this:
> obj: context [print: func [x][system/words/print ["***" x]]
That's it, yes.
> Because you are redefining the word print in the context of the
> object, all
> references to the word print in the object refer to the new definition.
> So if you just do this
> o: context [print: func [x][print ["***" x]]
> the interpreter goes into a stack recursion loop and you get a Stack
> overflow error. This is avoided by using system/words/print to
> refer to the
> global version.
I see a possible problem with patching over the 'source
function as I suggested.
If the code to redefine 'source was executed twice,
however it may happen, then the reference to the original
definition would be overwritten, and the function
would then be calling itself, resulting in a loop,
If there is some way for a function to know
whether it has been defined before, then we
could catch the redefinition.
We could use a "static variable"...
That needs an object wrapped around the
function and a flag word to remember if
the function was defined before.
(I feel sure this was discussed before, but I
wasn't up to the level at that stage.)
> > Anton.