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

Reflexology limits?

 [1/1] from: sunandadh::aol::com at: 30-Dec-2001 4:15


Rebol is a reflective language. The Core User Guide says, for example: Reflective Properties: The specification of all functions can be obtained and manipulated during run-time. ALL functions? That, and Romano's thread "Hack", got me thinking about (what Joel rightly named) a parlor game to test the limits of this statement. 1. Source of a Child function 1a. Print the source of an arbitrary named function before and after you call it That's so easy I'll solve it to get us started: Source ArbitraryFunction ArbitraryFunction Source ArbitraryFunction 1b. Ditto for an unnamed function 2. Source of the currently executing function Print it given .... 2a. ... it is a named function and it knows its own name (easy) 2b. ... it is a named function that does not know its own name. That is it should continue to work after this sequence: PrintSelf: func [] [...your code here...] PrintSelf ;; does exactly that ClonePrintSelf: :PrintSelf Unset 'PrintSelf ClonePrintSelf ;;Prints its own code (Hint: See Romano's Hack) 2. ... it is an unnamed function (same hint). 3. Source of Parent function Print the source of your parent (i.e. the function that called you), given .... 3.a ... your parent has a name. The following code is disqualified in advance: PrintParent: func [ParentFunc [word!]] [ source :ParentFunc] AnyFunc: func [] [PrintParent 'AnyFunc] Why? Because it isn't guaranteed to print the source of the parent, only the source of the word passed into it. 3.b ....your parent doesn't have a name. I can think of a (slightly contrived) reason why I'd want solutions to 3a and 3b....I want to write a function that only responds to authorised callers. A caller is assumed authorised if the length and checksum/secure of its molded source is on an approved list. And a happy new year to us all! Sunanda.