Bug? 'func not really 'func
[1/8] from: al:bri:xtra at: 9-Oct-2000 23:52
REBOL/View 0.10.38.3.1 3-Oct-2000
Copyright 2000 REBOL Technologies. All rights reserved.
>> source func
func: func [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg words (and opt type and
string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
>> first :func
== [spec body]
>> second :func
== [
throw-on-error [make function! spec body]
]
>> third :func
== [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg wor...
----^^^^^^^^^^^^^
Take special notice of "spec [block!]" here.
>> zot: func copy/deep third :func copy/deep second :func
-------------^^^^^^^^^^^^^^^
That should make a copy, shouldn't it? Let's check:
>> third :zot
== [
"Defines a user function with given spec and body."
[catch]
spec [datatype!] {Help string (opt) followed by arg ...
----^^^^^^^^^^^^^^^^
Hmmmm... That seems a little odd?!
>> source zot
zot: func [
"Defines a user function with given spec and body."
[catch]
spec [datatype!] {Help string (opt) followed by arg words (and opt type
and string)}
body [datatype!] "The body block of the function"][
throw-on-error [make function! spec body]]
>> test: zot [arg] [none]
** Script Error: zot expected spec argument of type: datatype.
** Where: test: zot [arg] [none]
>> f: func [arg] [none]
>> source f
f: func [arg][none]
Where did 'throw-on-error go to?! After all it's present here:
>> source func
func: func [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg words (and opt type and
string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
Looks like there's _two_ 'func in Rebol.
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
[2/8] from: al:bri:xtra at: 10-Oct-2000 0:55
> >> f: func [arg] [none]
> >> source f
> f: func [arg][none]
> Where did 'throw-on-error go to?! After all it's present here:
Silly Andrew! It didn't go anywhere.
But the rest of the bug is still there!! :-(
Andrew Martin
I blame my diabetic hypo...
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
[3/8] from: lmecir:geocities at: 10-Oct-2000 10:29
Hi Andrew,
1)
zot1: make function! [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg words (and opt type and
string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
source zot1
Result:
zot1: func [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg words (and opt type and
string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
2)
zot2: func load mold third :func copy/deep second :func
Load Mold is needed instead of Copy/deep (I think, that you will find out
why)
3)
FYI Throw-on-error simply executes, that's all.
HTH Ladislav
----- Original Message -----
From: <[Al--Bri--xtra--co--nz]>
To: <[list--rebol--com]>
Cc: <[feedback--rebol--com]>
[4/8] from: al:bri:xtra at: 10-Oct-2000 1:55
Ladislav wrote:
> FYI Throw-on-error simply executes, that's all.
I realised that shortly after I sent my email. Thanks!
> zot2: func load mold third :func copy/deep second :func
>
> Load Mold is needed instead of Copy/deep (I think, that you will find out
why)
I think I found out why:
>> type? block!
== datatype!
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/
[5/8] 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
<<quoted lines omitted: 13>>
> 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
[6/8] from: kgd03011:nifty:ne:jp at: 10-Oct-2000 20:01
Hi Andrew,
>> Load Mold is needed instead of Copy/deep (I think, that you will find out
>why)
<<quoted lines omitted: 4>>
>it's given. And also why it doesn't show up until after the function is put
>together.
COPY isn't evaluating the words in the block. The values in the "opt type"
subblocks of THIRD :FUNC are datatypes:
>> type? probe first fourth third :func
block!
== datatype!
whereas FUNC usually needs words in those subblocks. If you don't have a
word there, the contents of those subblocks are treated as samples of the
datatype:
>> cube: func [x [2 2.1]][x ** 3]
>> source cube
cube: func [x [integer! decimal!]][x ** 3]
LOAD MOLD, Ladislav's solution, converts the datatypes back to words.
Hope this makes some sense ...
Eric
[7/8] from: g::santilli::tiscalinet::it at: 10-Oct-2000 12:53
[Al--Bri--xtra--co--nz] wrote:
> >> third :zot
> == [
<<quoted lines omitted: 3>>
> ----^^^^^^^^^^^^^^^^
> Hmmmm... That seems a little odd?!
This is an old issue. Look:
>> type? first [block!]
== word!
>> third :func
== [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg wor...
>> fourth third :func
== [block!]
>> type? first fourth third :func
== datatype!
When MAKE FUNCTION! processes the spec, it does not leave the type
specifiers as words. Words are replaced by their values, while
other values are replaced with their datatype. For example:
>> f: func [a ["A string"]] []
>> third :f
== [a [string!]]
So, your BLOCK! above is not the word 'BLOCK! but the DATATYPE!
BLOCK!; since its type is DATATYPE!, it is replaced by DATATYPE!.
I think this should be considered as a bug, and DATATYPE! values
should be left as they are.
HTH,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[8/8] from: joel:neely:fedex at: 10-Oct-2000 21:54
[Al--Bri--xtra--co--nz] wrote:
[...actually useful content snipped...]
> Andrew Martin
> Falling prey to hypos...
>
Beats falling prey to hippos!
-jn-
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted