[REBOL] Re: source fails for object function
From: greggirwin:mindspring at: 12-Dec-2001 12:22
Hi Patrick,
<< - why does source fail ? >>
Source wants a word. Do "source source" at the console to see how it works.
<< - how one can test if two functions are identical ? >>
You can use the reflective properties of functions to retrieve their
internals and compare them. For example, I have a 'lib object, which
contains a 'math object, which, in turn contains a 'sign function. The 'in
function lets you retrieve the value of a word in a given context. Examples
speak louder than words so...
>> fn: get in lib/math 'sign
>> type? :fn
== function!
>> first :fn
== [value]
>> second :fn
== [
if positive? value [return 1]
if zero? value [return zero]
if negative? value [return -1]
]
>> third :fn
== [
{Returns: 1 if value is positive, -1 if value is negative, 0 if value is
0}
value [number! money! time!]
]
>> source fn
fn: func [
{Returns: 1 if value is positive, -1 if value is negative, 0 if value is
0}
value [number! money! time!]
][
if positive? value [return 1]
if zero? value [return zero]
if negative? value [return -1]
]
>> print mold get in lib/math 'sign
func [
{Returns: 1 if value is positive, -1 if value is negative, 0 if value is
0}
value [number! money! time!]
][
if positive? value [return 1]
if zero? value [return zero]
if negative? value [return -1]
]
The /Core docs talk about the reflective properties of functions, so that
would be a good place to look as well.
HTH!
--Gregg