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: sunandadh:aol at: 24-Mar-2002 15:10

> In rebol doc, it is said that function can know himself > (its argument, its code) but I can't see how it can know > just its name : it would seem logical that it is the firts > thing it should know :) ?
the "name" of a function is a problematic concept in Rebol. Take this code, for example: myfunc1: func [] [ print "what's my name?" do func [] [ print "what's _my_ name?" ] ; end unnamed func 0 / 0 ; cause error in myfunc1 ] ; end myfunc1 ;; we've just defined a function "called" myfunc1 that creates and executes ;; an unnamed function on the fly myfunc1 ;; we get an error message saying error in myfunc1. So far, so normal. myfunc2: :myfunc1 myfunc2 ;; But we've now assigned a second name to the function: both ;; myfunc1 and myfunc2 refer to the _same_ definition. myfunc3: do load mold :myfunc1 myfunc3 ;; Unlike this where myfunc3 is a different function same? :myfunc1 :myfunc2 same? :myfunc1 :myfunc3 equal? :myfunc1 :myfunc3 equal? mold :myfunc1 mold :myfunc3 ;; (A little mystery: why are :myfunc1 and :myfunc3 ;; different, but molds of them are equal?) ;; Next: make five copies of the function in a ;; block, and execute one of them. You could ;; argue that the name of the function is ;; myfuncs/5 -- but what if the block had no ;; name? myfuncs: copy [] loop 5 [append myfuncs :myfunc1] myfuncs/5 Sunanda.