|
Pages: [1]
|
 |
|
Author
|
Topic: series! scope issue (Read 439 times)
|
-X-
Guest
|
I intended this code to modify the index position a series! variable points to, but instead it does not modify the variable (returning a calculated value, rather than modifiying the actual series!). Why is this?, and how might I alter it to correalate to my original intention?
here's the code:
traverse: make function! [a1 [series!] a2 [integer!]] [ a1: skip a1 a2 ]
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
The index is related to the word, not its value, so what your function is doing is the same as this...
>> a: "abcd" == "abcd" >> b: skip a 2 == "cd" >> a == "abcd" >> b == "cd"
A and B each have an index, which references the string, but the string itself has no index.
Which only answers half of your question. :-) Not sure how to do what you want off the top of my head, but I suspect it's possible.
|
|
|
|
|
Logged
|
- Carl Read
|
|
|
Guest
Guest
|
Ok, more awake now, so here's one approach to doing what you want... traverse: make function! [a1 [word!] a2 [integer!]] [ set a1 skip get a1 a2 ] Note that A1 now expects a word, not a series, so we use the function like this... >> str: "abcd" == "abcd" >> traverse 'str 2 == "cd" >> str == "cd" >> head str == "abcd" Hope that's of use to you.
|
|
|
|
|
Logged
|
|
|
|
-X-
Guest
|
Yesterday it had occured to me that using word! might work, but at the time I didn't get the code for such working (course, I didn't try very much at the time though).
Anyway, I tryed your code, it works.
here's some more questions, as it were:
- If you use word! as the argument datatype, how would you code it so that the word must reference a series!?
- I would guess that the code is fast, but I'm wondering whether or not its the most efficient form?
- I thought "a1:" and ":a1" meant, literally "set a1" and "get a1", respectively. But substituting these seems to generate an error, is there some syntax rule differences here that I don't understand?
(I would look this stuff up again, myself, in the documentation, but I'm going to work on something else for a bit; but I'll post this for now, cause it might end up makeing things easier) _
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2240 Posts in 584 Topics by 2231 Members
Latest Member: BotOptomA
|