Rebol/Gotcha Handling previously defined words
[1/7] from: tim:johnsons-web at: 10-Dec-2003 10:30
Well, I did it again, and punished myself severely for the
transgression, but I can't bring back the time I lost....
I created a subroutine in a context and called it 'reduce. And I forgot
to either redefine or provide an absolute path for system/words/reduce.
Bad Tim, bad, bad Tim!
This poses the need for a wonderful one-liner that would throw an
error or warning in case a word is defined and used in a context that
already exists in system/words.
I'm just starting to dig into lisp as a part of learning emacs and I
believe that language does have such safeguards, but I haven't been able
to get to that understanding yet.
Any ideas? comments?
TIA
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
[2/7] from: carl:cybercraft at: 24-Dec-2003 22:51
On 11-Dec-03, Tim Johnson wrote:
> Well, I did it again, and punished myself severely for the
> transgression, but I can't bring back the time I lost....
<<quoted lines omitted: 9>>
> able to get to that understanding yet.
> Any ideas? comments?
I probably don't know what you mean, but doesn't PROTECT-SYSTEM do
this for you now?
--
Carl Read
[3/7] from: ammon:addept:ws at: 10-Dec-2003 12:51
No, because he isn't redefining the word in the global context but within
another context. In order to access the original reduce from within the
context he must use system/words/reduce.
HTH!
~~Ammon
[4/7] from: nitsch-lists:netcologne at: 10-Dec-2003 21:22
Hi Tim,
Am Mittwoch 10 Dezember 2003 20:30 schrieb Tim Johnson:
> Well, I did it again, and punished myself severely for the
> transgression, but I can't bring back the time I lost....
<<quoted lines omitted: 8>>
> to get to that understanding yet.
> Any ideas? comments?
You need a very long line for this, but
my.context: func [[catch]block /local ctx] [
ctx: context block
foreach word first ctx [
if all [value? w: in system/words word any-function? get w] [
throw make error! join "You don't want to redefine this: " word
]
]
]
ctx: my.context[a: b: none]
ctx2: my.context[a: reduce: none]
** User Error: You don't want to redefine this: reduce
** Near: my.context [a: reduce: none]
> TIA
-Volker
[5/7] from: nitsch-lists:netcologne at: 10-Dec-2003 21:36
Am Mittwoch 10 Dezember 2003 20:30 schrieb Tim Johnson:
Quickly fixing myself:
(forgot return-value, added object to checklist)
my.context: func [[catch] block /local ctx] [
ctx: context block
foreach word first ctx [
if all [
value? w: in system/words word
any [
; add your checks here
any-function? get w
object? get w
]
] [
throw make error! join "You don't want to redefine this: " word
]
]
ctx ; oops, never forget return value..
]
ctx: my.context [a: b: none]
? ctx
ctx2: my.context [a: reduce: none]
> TIA
-Volker
[6/7] from: maximo:meteorstudios at: 10-Dec-2003 16:27
this is a Q&D function for catching redefining words...
there are many things which can be added to this (like context handling), but I thought
of supplying the most basic idea and letting the imagination of others run loose ;-)
safe-func: func [word args body][
if value? in system/words word [
print ["WARNING function" uppercase to-string word "has been redefined"]
]
set in system/words word func args body
]
>> safe-func 'remove [arg1][probe arg1]
WARNING function REMOVE has been redefined
>> remove "HH"
HH
you can also protect all words with have a value before starting your script like so:
wordlist: query system/words
foreach word wordlist [
if value? in system/words word [
protect word
]
]
>> remove: true
** Script Error: Word remove is protected, cannot modify
** Near: remove: true
-MAx
---
You can either be part of the problem or part of the solution, but in the end, being
part of the problem is much more fun.
[7/7] from: tim::johnsons-web::com at: 10-Dec-2003 20:45
* Volker Nitsch <[nitsch-lists--netcologne--de]> [031210 12:08]:
> Am Mittwoch 10 Dezember 2003 20:30 schrieb Tim Johnson:
>
> Quickly fixing myself:
> (forgot return-value, added object to checklist)
Hiya Volker:
That looks like the right track to me.
Must check that out as soon as I'm done waltzing
with the snake.
Thanks very much!
tim
> my.context: func [[catch] block /local ctx] [
> ctx: context block
<<quoted lines omitted: 20>>
> To unsubscribe from this list, just send an email to
> [rebol-request--rebol--com] with unsubscribe as the subject.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted