Convert block inplace?
[1/5] from: robert:muench:robertmuench at: 25-Jul-2004 16:31
Hi, I'm trying to convert a block of values in place to other types.
Exmaple:
a: [%hi.txt %ho.txt]
convert-block a string!
should gibe:
a: ["hi.txt" "ho.txt"]
Some questions:
1. How can I change the block in place inside the function? I tried
'forall but I can't referr to the "current" entry.
2. 'swtich seems not to work with datatype! Is this a bug?
Robert
[2/5] from: SunandaDH:aol at: 25-Jul-2004 11:17
Robert:
> 1. How can I change the block in place inside the function? I tried
> 'forall but I can't referr to the "current" entry.
Something like this solves issue 1:
a: [%hi.txt %ho.txt]
for n 1 length? a 1 [
poke a n form a/:n
]
Sunanda
[3/5] from: nitsch-lists:netcologne at: 25-Jul-2004 17:24
On Sonntag, 25. Juli 2004 16:31, Robert M. Münch wrote:
> Hi, I'm trying to convert a block of values in place to other types.
> Exmaple:
<<quoted lines omitted: 5>>
> 1. How can I change the block in place inside the function? I tried
> 'forall but I can't referr to the "current" entry.
!>> a: [%hi.txt %ho.txt]
== [%hi.txt %ho.txt]
!>> forall a [change a to-string first a]
== []
!>> a: head a ;if you need 'a later
== ["hi.txt" "ho.txt"]
> 2. 'swtich seems not to work with datatype! Is this a bug?
No, obfuscation. the word string! and the datatype string! look the same in
console.
'type? gives the datatype, switch uses the word.
solutions:
1) switch type?/word .. ;
2) switch type? reduce[ string! [] .. ] ; reduces makes the word string! the
datatype string! (because [get string!] gives the datatype)
-Volker
[4/5] from: roland::hadinger::arcor::de at: 25-Jul-2004 17:55
On Sunday 25 July 2004 16:31, Robert M. Münch wrote:
> Hi, I'm trying to convert a block of values in place to other types.
> Exmaple:
<<quoted lines omitted: 6>>
> 'forall but I can't referr to the "current" entry.
> 2. 'swtich seems not to work with datatype! Is this a bug?
And for issue 2: made the same mistake... I guess you're trying:
switch type? element [
integer! [ ... ]
string! [ ... ]
...
]
If you look at the source code of the switch mezzanine, you'll see it's
basically just a 'do and a 'select. The select function takes a series as-is
and searches it (without reducing the series if it's a block). So everything
inside the switch block is either a word! or a block! (not a datatype!). You
have to reduce the switch block to get datatype! values.
switch type? element reduce [
integer! [ ... ]
...
]
HTH
--
R.
[5/5] from: robert:muench:robertmuench at: 25-Jul-2004 18:51
On Sun, 25 Jul 2004 17:24:33 +0200, Volker Nitsch
<[nitsch-lists--netcologne--de]> wrote:
>> 1. How can I change the block in place inside the function? I tried
>> 'forall but I can't referr to the "current" entry.
>
> !>> a: [%hi.txt %ho.txt]
> == [%hi.txt %ho.txt]
> !>> forall a [change a to-string first a]
Hi, argh, forgot about change. Seems I need to learn my Rebol vocabulary
more often. Thanks.
>> 2. 'swtich seems not to work with datatype! Is this a bug?
>
> No, obfuscation. the word string! and the datatype string! look the same
> in console. 'type? gives the datatype, switch uses the word.
Ok, use the source Luke. Thanks everyone. Robert
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted