[REBOL] Bug? 'func not really 'func Re:(3)
From: lmecir:geocities at: 10-Oct-2000 12:02
Hi,
[...snip...]
> I am confused as to why 'copy seems to be evaluating the words in the
block
> it's given. And also why it doesn't show up until after the function is
put
> together.
>
> BTW, here's a patch for 'function, to add 'throw-on-error around it, like
> 'does and 'func have:
>
> if not equal? second third :function [catch] [
> function: func
> head insert/only at load mold third :function 2 [catch]
> compose/deep [
> throw-on-error [
> (copy/deep second :function)
> ]
> ]
> ]
>
> Andrew Martin
> Falling prey to hypos...
> ICQ: 26227169
> http://members.nbci.com/AndrewMartin/
> -><-
>
1)
Not Copy, but Func evaluates its spec block to get the datatypes supplied,
instead of words. That is why you normally won't see the difference, but
look:
spec: [a [block!]]
type? probe first second spec
block!
== word!
f: func spec []
type? probe first second third :f
block!
== datatype!
Load Mold converts the datatype back to word.
2)
Your patch is not advisable in general. The reason:
x: 1
y: 0
z: 4
u: 2
f1: does [x / y]
f2: does [z / u]
trial: func [blk [block!]] [
probe do blk
]
trial [f1 f2]
Normally yields
** Math Error: Attempt to divide by zero.
** Where: x / y
, while
transformed-trial: func [[catch] blk [block!]] [
probe throw-on-error blk
]
transformed-trial [f1 f2]
yields:
** Math Error: Attempt to divide by zero.
** Where: transformed-trial [f1 f2]
, which may be useless for debugging. That is why error throwing is
advisable sometimes, but sometimes it isn't. Have a look at For source as an
example of balanced throwing, although the series bug I discovered still
remains unrepaired.
Regards
Ladislav