[REBOL] Re: Block as parameter
From: joel::neely::fedex::com at: 17-Aug-2002 8:52
Hi, Phil,
You've got something else happening to your data...
Philippe Oehler wrote:
> Hello RebList !
>
> I often pass as parameter a block to a function. The block is
> often the result of a read/lines function.
>
> The problem is that, when I pass this block as parameter, it
> seems that block is changed :
> Below,
>
> a: read/lines %theTXT.txt
> length? a ; --> 12 ; because of 12 lines
>
> but when i pass 'a to a function the result is :
>
> make-this: func [the-block] [
> print length? the-block; ----> 120
> ; because for example, my txt has a 10
> ; column structure
>
> ]
>
> make-this a
>
> How could I keep the block intact, without any transformation ??
>
As you can see below, I can't reproduce your described problem:
>> someblock: [
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ "0123456789"
[ ]
== [
"0123456789"
"0123456789"
"0123456789"
"0123456789"
"0123456789"
"0123456789"
"0123456789"
...
(twelve entries of ten characters each)
>> length? someblock
== 12
>> make-this: func [the-block] [
[ print length? the-block
[ ]
>> make-this someblock
12
Both give the correct length of the block. OTOH, remember that
blocks are mutable, so if we pass a block to a function that
modifies its content/structure, then that change will persist.
Are you sure there's nothing like that happening in your
original code?
-jn-
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]