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

Redefining system words - gotchas

 [1/13] from: tim-johnsons:web at: 26-Apr-2007 14:01


Howdy: Here's an example: I want to redefine 'pick so that pick series -1 gets the last element pick series -2 gets the second to last etc... If the source for my redefined 'pick is in a file, let's call it std.r and we have the following code: sys-pick: get in system/words 'pick Now if 'sys-pick is in my code for the redefined 'pick and I do %std.r a second time before closing the interpreter, I will get a stack overflow because on the second 'do 'pick is already redefined. The workaround for this is: if not value? 'sys-pick[ sys-pick: get in system/words 'pick ] the works, but the gotcha is that if I'm working with a large application that has somehow previous defined 'sys-pick errors could be introduced. This scenario is not likely, especially if one sticks to a strict taxonomic convention of redefining system words as 'sys-word, but I'd welcome comments on this situation. thanks tim Long live the mailing list :-) -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA

 [2/13] from: gregg::pointillistic::com at: 26-Apr-2007 17:03


Hi Tim, TJ> I want to redefine 'pick so that pick series -1 gets the last TJ> element pick series -2 gets the second to last etc... TJ> ...the gotcha is that if I'm working with a large application that TJ> has somehow previous defined 'sys-pick errors could be introduced. I've become leery of redefining system words at a global level, especially in larger projects, but I know that's part of the appeal of REBOL; so I would suggest using Ladislav's INCLUDE function, that allows you to specify that something should not be loaded if it already has been. -- Gregg

 [3/13] from: tim-johnsons:web at: 26-Apr-2007 16:16


On Thursday 26 April 2007 23:03, Gregg Irwin wrote: errors could be introduced.
> I've become leery of redefining system words at a global level, > especially in larger projects, but I know that's part of the appeal of > REBOL; so I would suggest using Ladislav's INCLUDE function, that > allows you to specify that something should not be loaded if it > already has been.
Hi Greg: I've already got that functionality: ;; ------------------------------------------------------------------- load-with-path 'file: 'do file, if not already loaded, and not found in local folder search a block of paths. ;; ------------------------------------------------------------------- import 'word: converts 'word to %file + .r and calls load-with-path ;; ------------------------------------------------------------------- modules {space-delimited words in string} - multiple functionality also leverages load-with-path and has built-in debugging. One could put a keywork into the docstring and then I could look for a keyword in third :pick ..... that is, parse the docstring. thanks tim -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA

 [4/13] from: tim-johnsons::web::com at: 26-Apr-2007 16:38


Something I forgot to mention.... There's a corollary to this subject. I have a whole lot of code that uses the word path. Sometime - I think with REBOL/Core 2.6.2.4.2 - a native value called 'path has been introduced. This has sometimes raised hell with my legacy code.
>>help path ;; gives me
USAGE: PATH value selector DESCRIPTION: Path selection. PATH is an action value. ARGUMENTS: value -- (Type: any) selector -- (Type: any) Don't know any more about it. Can't find any documentation on it. But as you can see - introducing a new word from the binary can cause problems too... tim -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA

 [5/13] from: anton::wilddsl::net::au at: 27-Apr-2007 16:27


Hi Tim, Do you need 'sys-pick to point to the original ? How about this: if action? :pick [pick: ...] Keep in mind the whole world of rebol code is expecting PICK to be the built-in one. Why not just define 'my-pick or 'tj-pick and leave poor 'pick alone ? Anton.

 [6/13] from: santilli::gabriele::gmail::com at: 27-Apr-2007 11:09


2007/4/26, Tim Johnson <tim-johnsons-web.com>:
> >>help path ;; gives me > USAGE: > PATH value selector
[...] It should not be there, and if you just redefine (or UNSET) it nothing bad should happen. (You could just UNSET it at the beginning of your code if it's causing problems.) HTH, Gabriele.

 [7/13] from: tim-johnsons:web at: 27-Apr-2007 7:33


On Friday 27 April 2007 06:27, Anton Rolls wrote:
> Hi Tim, > > Do you need 'sys-pick to point to the original ? > How about this: > > if action? :pick [pick: ...] > > Keep in mind the whole world of rebol code is expecting > PICK to be the built-in one.
Of course!
> Why not just define 'my-pick or 'tj-pick and leave poor 'pick alone ?
ugh! not good choices... for my taste anyway. My question is kind of academic, for a global word, I would "pick" a different one. My choice turned out to be "peek". for the sake of anyone reading the thread however, I must include that there is much code written where system words have redefined. Where I think it is most safe to do so is inside of a context. thanks tim -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA

 [8/13] from: tim-johnsons::web::com at: 27-Apr-2007 7:38


On Friday 27 April 2007 09:09, Gabriele Santilli wrote:
> 2007/4/26, Tim Johnson <tim-johnsons-web.com>: > > >>help path ;; gives me
<<quoted lines omitted: 5>>
> bad should happen. (You could just UNSET it at the beginning of your > code if it's causing problems.)
Hi Gabrielle: I'm curious, are you saying that 'path isn't really a viable rebol native function? I notice that >> native? path ;; return false while >> native? while ;; as an example only ;; returns true If so, how did that docstring get in there? Asking 'cuz I think you're working directly with the binary "C" code. Thanks tim -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA

 [9/13] from: santilli:gabriele:gm:ail at: 27-Apr-2007 18:08


2007/4/27, Tim Johnson <tim-johnsons-web.com>:
> I'm curious, are you saying that 'path isn't really a viable rebol native > function? I notice that >> native? path ;; return false > while >> native? while ;; as an example only > ;; returns true
It's an action!, not a native!, that's why native? returns false. But, the point is that it is an internal action, that is not supposed to be used by users. It was being unset in older rebols but it is not in newer versions. It should be safe to unset it.
> If so, how did that docstring get in there? > Asking 'cuz I think you're working directly with the binary "C" code.
I'm not, but I can guess. I've seen some bits of C code so I know that the docstrings are embedded in C comments; I guess Carl has a script that extracts them and builds the rebol code that "defines" the natives (see the other "mysterious" function called "native"). So since the whole process is automatic, PATH is there even if it should not. :) Regards, Gabriele.

 [10/13] from: jblake:arsenaldigital at: 27-Apr-2007 12:46


How about "pick-next" or "pick-last"?

 [11/13] from: dhsunanda:g:mail at: 27-Apr-2007 18:57


Tim:
> This scenario is not likely, especially if one sticks to a strict taxonomic > convention of redefining system words as 'sys-word, but I'd welcome > comments on this situation. > thanks > tim
We have exactly the same situation in the CGI base for REBOL.org: ** we have a large number of CGI scripts, many of which were written as "top level" but now are called from other scripts....So we can never assume any given script has the sole responsibility for initialising or terminating processes; ** we incorporate other people's code as far as possible without having to modify the code. That means we need wrappers in some cases to remove actions that are unsuitable for CGI scripts -- we don't want (say) makedocpro doing a Print into the middle of our HTML output stream. Our solution is almost identical to yours: do-if 'sys-pick[ sys-pick: get in system/words 'pick ] do-if executes the block if the word is *not* defined.....So you'll see the Library CGI code littered with 'do-if statements rather than 'do. It's not perfect, but it works for us. Sunanda.

 [12/13] from: tim-johnsons::web::com at: 27-Apr-2007 10:33


On Friday 27 April 2007 16:46, John Blake wrote:
> How about "pick-next" or "pick-last"?
<grin> Less typing, but verbosity lends to self-documentation.... -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA

 [13/13] from: tim-johnsons::web::com at: 27-Apr-2007 13:55


On Friday 27 April 2007 17:57, Sunanda wrote:
> Tim: > do-if executes the block if the word is *not* defined.....So > you'll see the Library CGI code littered with 'do-if statements > rather than 'do. > > It's not perfect, but it works for us.
Hey :-) 'do-if and 'set-if should be part of my rebol 'dialect'. thanks tim -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted