Re: Calling Func/Proc
- Posted by c.k.lester <euphoric at ckle?ter.com> Jul 12, 2007
- 640 views
Robert Craig wrote: > > I don't think we want to start > adding features that are not supported by the Translator, > unless there is a very good reason for it. I agree. > Is it that inconvenient to just add a parameter to the routine, > or set a global variable with the name of the calling routine? It is inconvenient and would violate the DRY principle. (http://en.wikipedia.org/wiki/Don't_repeat_yourself) I would have to add parameters to hundreds of routines. > Can we see some examples of where this would be useful. C.K.? I have a procedure called err() that gets passed an error message. err() is called from hundreds of functions and procedures all spread throughout my code. I usually call it like in this small example: function rev_string(sequence x) if length(x) = 0 then err("rev_string(): Must be at least 1 character in length." else if length(x) > 17 then err("rev_string(): String too long." else x = reverse(x) end if end if return x end function A "fixed" version would look like this: function rev_string(sequence x) if length(x) = 0 then err("Must be at least 1 character in length." else if length(x) > 17 then err("String too long." else x = reverse(x) end if end if return x end function This is a very short example. When dealing with a much larger func/proc, there may be many more calls to err. Sometimes I change the name of a func/proc. When that happens, I also have to adjust all the calls to err. You suggest something like this: function my_super_function() CURR_ROUTINE = "my_super_function" --or set_routine_name( "my_super_function" ) ... end function but that violates DRY and, again, would have to be done for hundreds of func/proc in my code. It is unnecessary overhead to something that should be quite simple to resolve. What about if I want to trace the call back a few func/procs? It makes manual tracking even more complicated and time consuming. Say that a calls b calls c which calls my_super_function... To track the progress, you need something like: function my_super_function() add_routine_name( "my_super_function" ) -- do your stuff remove_routine_name( "my_super_function" ) end function I'm open to suggestions, but the fact is, the most efficient way to do this tracking of func/proc hierarchy is to let the interpreter/translated program handle it. The reason I need it is primarily for error handling/messaging and debugging.