Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: series! scope issue
Pages: [1] Print
Author Topic: series! scope issue  (Read 491 times)
-X-
Guest


Email
series! scope issue
« on: February 11, 2006, 06:28:47 PM »

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
Full Member
***
Offline Offline

Posts: 105


View Profile
series! scope issue
« Reply #1 on: February 11, 2006, 08:23:00 PM »

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


Email
series! scope issue
« Reply #2 on: February 13, 2006, 01:36:15 AM »

Ok, more awake now, so here's one approach to doing what you want...

Code:
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


Email
series! scope issue
« Reply #3 on: February 13, 2006, 09:02:57 AM »


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] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: series! scope issue
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2008, 08:22:43 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2315 Posts in 597 Topics by 4203 Members
Latest Member: fn2000 assault rifle

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc