Hi Eric,
>Speaking of datatypes, here's a puzzle! (If you're sick of puzzles, think
>of it as a conundrum ;-)
>
>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

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):

>>>>>>> Gabriele:

>> print mold :make_average_obj
func [/local data][
    data: copy [] 
    sum: func [numbers] [either tail? numbers [0] [(sum next numbers) + first 
            numbers]] 
    make object! [
        add_integer: func [value [integer!]] [append data value true] 
        average: func [] [(sum data) / (length? data)]
    ]
]
>> print mold a

make object! [
    add_integer: func [value [integer!]][append data value true]
average: func [][(sum data) / (length? data)]
]
>> b: make_average_obj
>> print mold :make_average_obj
func [/local data][
    data: copy [] 
    sum: func [numbers] [either tail? numbers [0] [(sum next numbers) + first 
            numbers]] 
    make object! [
        add_integer: func [value [datatype!]] [append data value true] 
        average: func [] [(sum data) / (length? data)]
    ]
]
>> print mold b

make object! [
    add_integer: func [value [datatype!]][append data value true]
average: func [][(sum data) / (length? data)]
]
>> print mold a

make object! [
add_integer: func [value [datatype!]][append data value true]
average: func [][(sum data) / (length? data)]
]

integer! becomes datatype! after the second call to the function.
I havo no idea about the reason, but it seems like the block
[integer!] is somehow reduced...

<<<<<<<<<<<<<<<<< End Gabriele

This appears to have been fixed with respect to objects. The current
version of REBOL acts as expected:

>> print mold :make_average_object
func [/local data][
    data: copy []
    sum: func [numbers] [either tail? numbers [0] [(sum next numbers) + first
            numbers]]
    make object! [
        add_integer: func [value [integer!]] [append data value true]
        average: func [] [(sum data) / (length? data)]
    ]
]

>> print mold :a

make object! [
add_integer: func [value [integer!]][append data value true]
average: func [][(sum data) / (length? data)]
]
>> print mold :b

make object! [
add_integer: func [value [integer!]][append data value true]
average: func [][(sum data) / (length? data)]
]

Note that in Gabriele's example above, print mold :b contained the line:
    add_integer: func [value [datatype!]][append data value true]
whereas in version 2.2 the line is now:
    add_integer: func [value [integer!]][append data value true]

The type specifier integer! has been preserved and was not replaced by
[datatype!].

Apparently, REBOL continues to replace integer! by datatype! when make
function! has been evaluated. In your example, REBOL returns:

>> array2: func third :array second :array
>> print mold :array2
func [
    "Makes and initializes a series of a given size."
    size [datatype! datatype!] "Size or block of sizes for each dimension"
    /initial "Specify an initial value for all elements"
    value "Initial value"
    /local block rest
][
    if not initial [value: none]
    rest: none
    if block? size [
        rest: next size
        if tail? rest [rest: none]
        size: first size
        if not integer? size [make error! "Integer size required"]
    ]
    block: make block! size
    either not rest [insert/dup block value size
    ] [
        loop size [
            block: insert/only block array/initial rest value
        ]
    ]
    head block
]


Note the line:
    size [datatype! datatype!] "Size or block of sizes for each dimension"


I think it's a bug Eric, which is why I'm not sure it really qualfies as a
"puzzle".

;- Elan >> [: - )]

Reply via email to