[REBOL] an awful 'to-word bug...
From: Christophe::Coussement::mil::be at: 8-Sep-2003 10:10
Hi list,
I just spent about one hour to find this awful bug into my code, which I want to share
with the list.
SITUATION:
---------
I'm loading data from a SQL Server table containing a field "label" in char(30), which
results in something like:
string-label: ["label1 " "label2 "]
I wanted to use those to _labelize_ some data in to a block, so i did:
>> a-block: copy []
>> foreach label string-label [append a-block reduce [to-word label "test"]]
which should have result:
>> a-block
== [label1 "test" label2 "test"]
but
>> a-block/label1
** Script Error: Invalid path value: label1
** Near: a-block/label1
OBSERVATION:
-----------
the content of a block was not as expected, but was initially attributed to a REBOL formatting
problem:
>> a-block
== [label1 "test" label2 "test"]
SOLUTION:
--------
There was no formatting problem, but the 'to-word function did not execute any trim before
converting the string! into word!, so
>> a-block/label1
couldn't possibly work, as a-block/label1........24 spaces..... should have
Solution is then obvious (aren't they always once you found the problem :) ): 'trim the
string
>> string-label: ["label1 " "label2 "]
>> a-block: copy []
>> foreach label string-label [append a-block reduce [to-word trim label "test"]]
== [label1 "test" label2 "test"]
>> a-block/label1
== "test"
Hopes this information helps someone !
CU,
==xtof