Hi Elan,

>I don't really think this qualifies as a puzzle, does it? A similar
>phenomenon was discussed in June 1999, first reported by Gisle. Gabriele
>pointed out at the time (We are speaking REBOL version 2.0 or 2.1):

Guess not, but it's a subject I'm interested in.

Thanks for the quotes - that was about a month before I first joined the
list. I went back to the earliest version I have, and that's how it works
all right. Very interesting.

Anyway, here's how I understand the question I raised.

>>Why does this happen?
>>
>>>> array2: func third :array second :array
>>>> array2 8
>>** Script Error: array2 expected size argument of type: datatype datatype.
>>** Where: array2 8

It happens is that you can specify datatype arguments in the SPEC argument to
FUNC with either words, or datatype samples:

>> source f
f: func [x [integer!]][x * x]
>> f: func [x [6]][x * x]
>> source f
f: func [x [integer!]][x * x]

The result is exactly the same. If you specify the type of X with a word,
REBOL will get the value of the word, and use it only if that value is
a datatype:

>> f: func [x [y]][x * x]
** Script Error: Invalid argument: y.
** Where: func [x [y]] [x * x]
>> y: decimal!
== decimal!
>> f: func [x [y]][x * x]
>> source f
f: func [x [decimal!]][x * x]

Now once you've created a function, the specification of the function can
be accessed with THIRD, and in that "compiled" specification the word or
datatype sample originally used has been replaced with the datatype itself:

>> third :f
== [x [decimal!]]
>> first second third :f
== decimal!
>> type? first second third :f
== datatype!

So if you try to recycle THIRD :F to construct a new function, REBOL will
see a datatype, and use that as a sample in creating a new function:

>> ff: func third :f second :f
>> source ff
ff: func [x [datatype!]][x * x]

Perhaps that should be considered a bug - it would be much more intuitive
for REBOL to simply use the datatype as is, rather than interpreting it
as a datatype sample.

Sorry to go on about such an arcane subject!

Later,
Eric

Reply via email to