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: lmecir:mbox:vol:cz at: 27-Mar-2002 17:37

Hi Laplace, I will try to give you an exhaustive answer: a) Rebol functions are anonymous, i.e. they do not have names, although you can set any Rebol word to refer to any Rebol function b) it is easy to do what you described, there is a whole lot of ways how to program that in Rebol: b1) generic-function: func [function-name [word!]] [ do get function-name function-name ] func1: func [function-name [word!]] [ instruction11 instruction12 print function_name instruction13 ] func2: func [function-name [word!]] [ print function_name instruction21 ] b2) another possibility is to use the error handling mechanism as described by Carl b3) it is easy to make your own functions that do have a name attribute (I can explain how, if you really need it) etc. Cheers L ----- Original Message ----- From: "laplace" To: <[rebol-list--rebol--com]> Sent: Tuesday, March 26, 2002 7:54 PM Subject: [REBOL] Re: Reflectivity: How a function can know its own name ? Hello thanks for the code. I will be useful for me since I just began to look at Rebol. Nevertheless my problem is in fact to know the name of the function FROM INSIDE the function because I want to do something like this (see my first anwer to the thread I suppose that an instruction name of self is implemented for rebol function): 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 ] ]