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

[REBOL] Re: Reflectivity: How a function can know its own name ?

From: laplace:worldnet at: 26-Mar-2002 19:43

Thanks for your answer. In your examples you show that in SOME cases, the name concept can be a problem. But It would seem logical for me that the system implements an instruction for a function to know its own name when it is possible. This is useful for generic programming with encapsulation style (polymorphism). What I want to do is to be able to have a serie of functions calling within their own context a generic function which will behave differently depending on the name of the caller function. The place and the way each function will call this generic function will vary. Suppose name of self exists for function I could do: generic_function: make function ['function_name] [ print function_name ] func1: make function! [ instruction11 instruction12 generic_function [name of self] instruction13] func2: make function! [generic_function [name of self] instruction21 ] ... func10: make function! [ instruction31 generic_function [name of self]] ---- If I don't have a "name of self" for function, each time I add a new function to call generic function, it is in the code of generic function that I would have to test the name of the function with a more or less gigantic number of test instructions: generic_function: make function ['function_name] [ if function_name = "func1" [ instruction11 instruction12 print function_name instruction13 ] if function_name = "func2" [ print function_name instruction21 ] ]