[REBOL] Re: Improved SOURCE function
From: larry:ecotope at: 5-May-2001 23:59
Hi Anton
> Good idea Larry,
:-)
> I saw somewhere how to refer to inbuilt word
> if you are redefining a word.
> If you can refer this way to source, then
> you can truly patch the source word.
>
> Something like (pseudo-code):
>
> source: func [word][
> either it's-a-path? word [
> ; all your patching code
> ][
> ; use the inbuilt 'source function
> system/.../source word
> ]
> ]
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.
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:
http://www.nwlink.com/~ecotope1/reb/src.r
> 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]]
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.
Regards
-Larry