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

[REBOL] Re: Hack

From: joel:neely:fedex at: 28-Dec-2001 17:34

Hi, Sunanda, [SunandaDH--aol--com] wrote:
> That's clever stuff... >
I'm not trying to be "clever" to be difficult! ;-) My concern, which I probably didn't state well, is that I'd rather see a mechanism that works for the general case of anonymous functions (even if -- and I agree with you -- the majority of code uses defined-and-named-once functions) rather than have a tool that only works in the simple cases.
> ...but I think it misses the point I'd like > to make. Take these three functions: > > FuncA: func [] [2 / 2 FuncB] > FuncB: func [] [2 / 2 FuncC] > FuncC: func [] [2 / 2] > > Change any of those 2 / 2 to 2 / 0, invoke FuncA and you'll get > a message like: > > ** Math Error: Attempt to divide by zero > ** Where: FuncC > ** Near: 2 / 0 > > With the 'Where giving me the name of the function. The only way > we know to get that name is (see Romano's original post) to force > an error. >
But, see below...
> That is not a first-class API in my opinion <g>... >
Agreed. Absolutely.
> I agree that if a function isn't named then Rebol can't show a > name....But it doesn't follow that therefore it can't give me > any names at all, ever. >
But it does raise in my mind the question of whether the name is as meaningful as some other possible information we might get. Consider the following...
>> f: reduce [
[ func [x] [x / divisor + 1] [ func [x] [x / divisor + 2] [ func [x] [x / divisor + 3] [ ] == [func [x][x / divisor + 1] func [x][x / divisor + 2] ...
>> foreach ff f [print ff 4]
3 4 5
>> divisor: 0
== 0
>> foreach ff f [print ff 4]
** Math Error: Attempt to divide by zero ** Where: ff ** Near: x / divisor + 1 Knowing that I happened to have accessed the function via the (temporary!) reference in a word named FF is of little use, if what I am really trying to do is find (and, presumably, fix) the defective code. Also, consider the following...
>> do func [x][x / divisor + 4] 5
** Math Error: Attempt to divide by zero ** Where: func [x][x / divisor + 4] ** Near: x / divisor + 4
>> g: func [n [number!]] [
[ if 0 < do func [x][x / divisor + 4] n [ [ print "positive" [ ][ [ print "non-positive" [ ] [ ]
>> g 5
** Math Error: Attempt to divide by zero ** Where: func [x][x / divisor + 4] ** Near: x / divisor + 4 in which "Where:" doesn't even have a name, because there isn't one at all. By way of contrast, let me mention the behavior of the CALLER function in Perl. It accesses information in the "stack of current subroutine calls", which includes the source file name and line number of each pending evaluation. Knowing where a function is defined seems to me to be at least as useful as what name the caller may have used to get to it... Just my $0.02... -jn-