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

[REBOL] Re: Load of trouble?

From: rotenca:telvia:it at: 30-Nov-2001 2:11

Hi, Colin
> That doesn't shut the console down, but a canadian or UK postcode will
raise
> an error: > > raw-input: " W1A 4AA " > date? cleaned-input: first load/all raw-input > > ** Syntax Error: Invalid integer -- 4AA > ** Near: (line 1) W1A 4AA
The point is that 4AA is interpreted like an integer because it starts with a digit, but then the conversion fails (A can be in a integer). No Rebol datatype! match 4AA. The difference between Load and To-Word is that To-Word creates a global word with any sequence of chars: to-word "123" creates the global word! '123, while Load interprets "123" like an integer!.
> But using 'load at all introduces a subtle problem. Each 'load of a
raw-input
> string potentially adds entries to System/Words. When that reaches about > 4000, the system crashes. Unrecoverably.
You must use to-block which make the same check of load about datatypes but doesn't add the words to the global context. These kind of words can be called unloaded words or "masked words" (there is not an ufficial name for them). The drawback is that the words generated by to block are out of context and to use them like variable you must first bind them to any context (object function use, not global of course). I have written some func to use this kind of words. You will find them in my rebsite (Romano) under the name gcmask.r http://web.tiscali.it/anarkick/gcmask.r Recently i have found a bug in Rebol which crashes the interpreter when you try to Set or Get a masked word out of context, instead of generating the error "the word is not defined in this context". So do not try to Set or Get this type of words (unloaded and undefined word) before adding them to a local context; you can use them like set-word (to get an error not a crash) but not use them with the functions Set or Get. Probably Set presumes that the word is in the global context. The thing is bad because you must assicure that no func Set or Get the unloaded and undefined word. Is high probable that a function like Layout will set/get the word if you try to use it in the layout definition.
> Which means the code above can't be 24x7 on a server. And it won't last more > than a few hundred lines if it's part of a clean-up operation on an incoming > text file.
The solution: use to-block to create unloaded words. A consequence of this is that often (not always) you have to manipulate them in strings, not in block (but here you will not have any problem :-)
> So (my conclusion) is that 'load for validation of raw data is a dead end.
I agree.
> And if I'm going to continue using Rebol, I need to buckle down and write > some serious data validation code first. Or RT need to rethink System/Words.
At least RT should correct the set bug. Perhaps there are other Rebol bugs connected to the use of unloaded words, but i not sure. --- Ciao Romano