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

[REBOL] Re: Better error messages?

From: nitsch-lists:netcologne at: 8-Dec-2001 14:08

RE: [REBOL] Re: Better error messages? [SunandaDH--aol--com] wrote:
> Hi Volker, > > > Interesting point. > > thats more the job of logging then of error-messages? > > i played a bit with it, and now there is a prototype > > http://www.reboltech.com/library/scripts/error-logger.r > > on the script-library. > > your function would look like > > displayscreen: func [[catch] p-type /local line-count] [ > > mission "displaying screen" [ > > switch p-type [ > > "A" [Line-Count: Line-Count + 1] > > ] > > ] > > ] > > then and on error logs its mission-goal and the error to %error-log.txt . > > of course you have to customize it ;-) > > Interesting reply! Thanks for putting the work in. That's an approach that > solves the problem. >
Oh, thank you :)
> And it gets me wondering if it could be done the other way round. For > example, I define a function called (say) LoggedFunc: > > LoggedFunc: func [Params ExecuteBlock] [Implementation] > > which I can use as normal: > > displayscreen: Loggedfunc [p-type /local line-count] [ > switch p-type [ > "A" [Line-Count: Line-Count + 1] > ] > ] > > The [Implementation] stacks that "DisplayScreen" has been called, TRYs the > ExecuteBlock as a normal Func, and unstacks the call on 'Return. And, of > course, prints the stack on error. > > This would be less "intrusive", and could easily be "turned off" for high > performance (LoggedFunc: :func I think would nix it). > > Trouble is I got not idea how to do it. Or rather, I see a some of difficult > problems: > > -- How to get the function name as a string?
either Loggedfunc: func[word args block][set word func args block] displayscreen: none ;mark it for context Loggedfunc 'displayscreen [p-type /local line-count] [ switch p-type [ "A" [Line-Count: Line-Count + 1] ] ] (ugly) or Loggedfunc: func['word args block][word func args block] Loggedfunc displayscreen: [p-type /local line-count] [ switch p-type [ "A" [Line-Count: Line-Count + 1] ] ] hack: we use a set-word, so make object! recognizes our word as local. not real rebol, only one prefix function, not really good. or something like my-context: logging context[ displayscreen: Loggedfunc [p-type /local line-count] [ switch p-type [ "A" [Line-Count: Line-Count + 1] ] ] ] ] 'logging easy to forget, but i like it most. and now i develop magic: (starts mumbling, various miraculous words later:) { AND WITH MORE SERVICE (update to http://www.reboltech.com/library/scripts/error-logger.r 1.1.0) } Initcode2: LOGGING context [ displayscreen: LOGGED func [p-type /local line-count] [ switch p-type [ "A" [Line-Count: Line-Count + 1] ] ] ] { 'LOGGED sets a marker 'its-a-logging-func in the functions body. 'LOGGING scans all functions in objects for marker and modifies them to use 'mission. RESULT: } Initcode2: make object! [ displayscreen: func [[catch] p-type /local line-count] [ mission "displayscreen:" [ switch p-type [ "A" [Line-Count: Line-Count + 1] ]]] ] {oh yes, to disable logging use} logging: logged: func [arg] [:arg]
> -- How to pass refinements? > -- How to distinguish LoggedFun's /Locals from my functions locals?
simple: pass nothing :) i take a ready-made and bound function and modify its body. because i add my words after binding, the same name can be used local and in my context. (similar to using the same index with two different arrays). so using 'mission local should be ok. only problem is 'its-a-logging-func, so it has a hopefully rare name. could be checked smarter, because same? (in my-context 'its-a-logging-func) (in another-context 'its-a-logging-func) gives false, but then the code gets more complex. also i can use displayscreen: func [p-type /local line-count] [ 'ITS-A-LOGGING-FUNC switch p-type [ "A" [Line-Count: Line-Count + 1] ] ] by hand this way. don't know if it makes sense..
> Any help on this would again be greatly appreciated. > > Thanks again, > Sunanda.
Have a lot of fun in the field :) -Volker