[REBOL] make list 0 versus make list [] Re:
From: al:bri:xtra at: 28-Aug-2000 15:20
Terrence "Perl Refugee" Brannon wrote:
> I read something in the REBOL McGraw-Hill book, but would like to verify
it.
> Is there a difference on subsequent invocations of a function if I bind a
(local?) value using make list! 0 versus make list! []
> So, now I have created 4 cases:
>
> make list!.....0 or []
> the word being defined...../local to function or global to rebol
>
> If I could get an answer to all four of these cases, I would be a much
clearer on state retention between function invocations.
With this:
make list! 999
the number 999 suggests to Rebol how much space to allocate to the list.
With this:
make list! []
the "[]" suggests to Rebol that no minimum size of memory be allocated
to the list!.
In both cases, Rebol will expand or contract the list as required to hold
the data in the list.
If you want to make the word local to the function, then:
MyListFunction: function [] [MyList] [
MyList: make list! 999
;...
]
If you want to make the word global:
MyListFunction: function [] [] [
MyList: make list! 999
;...
]
In both of the above functions, the 'MyList word is allocated a new 'list!
each time the function MyListFunction is invoked. If you want to keep the
same list, each time the function is invoked, put:
MyList: make list! 999
outside of MyListFunction. Better still, use a object!:
MyList: make object! [
MyList: make list! 999
MyOperation: function [] [] [
;...
]
]
Andrew Martin
ICQ: 26227169
http://members.xoom.com/AndrewMartin/