r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

BrianH
23-Mar-2008
[9548]
The only difference between SKIP+ and EXTRACT related to bounds checking 
is that you can generate out-of-bounds references with SKIP+ using 
the start parameter, where with EXTRACT you would not be able to.
[unknown: 5]
23-Mar-2008
[9549]
I see other problem potentials for extract.   If the position value 
could ever be user supplied it causes a major problem.
BrianH
23-Mar-2008
[9550]
How so, and what do you mean?
[unknown: 5]
23-Mar-2008
[9551]
maybe not really as it does seem to truncate to the values
BrianH
23-Mar-2008
[9552]
You are using fixed-length records, right? Are there circumstances 
where the last record might be less than the fixed length? If so, 
what does that mean? Are the values considered missing?
[unknown: 5]
23-Mar-2008
[9553x2]
Not sure fixed length records
sure = using
BrianH
23-Mar-2008
[9555]
EXTRACT and SKIP+ extract values at fixed intervals, so that means 
you use them with series that are formatted in fixed intervals. Thus, 
fixed-length records.
[unknown: 5]
23-Mar-2008
[9556]
Well skip+ is not designed to need a fixed set of records towards 
its interval
BrianH
23-Mar-2008
[9557]
Yes, it is. Only the last record can be variable length.
[unknown: 5]
23-Mar-2008
[9558]
I assume you mean by fixed length that the series will be fixed to 
an even distribution of whatever the skip interval is.
BrianH
23-Mar-2008
[9559]
No, I mean the interval itself.
[unknown: 5]
23-Mar-2008
[9560]
Skip+ doesn't require is series to be fixed to the interval.
BrianH
23-Mar-2008
[9561x2]
>> blk: [1 2 3 4 5 6 7 8 9 10]
== [1 2 3 4 5 6 7 8 9 10]
>> skip+ blk 2 1
== [1 3 5 7 9]

You are treating the series as a series of records of length 2.
That is what the interval does, just like EXTRACT.
[unknown: 5]
23-Mar-2008
[9563x2]
I don't look at it that way.  I look at that I have a variable length 
of records in blk and I want to return every second one.
Probably just in how we relate to it.
BrianH
23-Mar-2008
[9565x2]
If the values in the series are themselves variable-length records, 
that's nice, but it doesn't affect what skip+ or extract does.
I'm only concerned with how you are treating the series itself.
[unknown: 5]
23-Mar-2008
[9567x2]
Ok Brian.  Hey the rebol community has extract and at least I have 
extract and skip+ so I'm happy.
I almost brought up my replace-all function.  Could have been here 
for the next year discussing that one.
BrianH
23-Mar-2008
[9569]
How is it different from replace/all ?
[unknown: 5]
23-Mar-2008
[9570x2]
b: [[1] [[[1]]] [1]]
how do you replace/all the 1's in that with 2's?
BrianH
23-Mar-2008
[9572]
I'd probably use parse, or Gabriele's rewrite function. How did you 
do it?
[unknown: 5]
23-Mar-2008
[9573]
Mine is strictly a replace/all function it is much more tasking on 
the system but if made native could probably be cool
BrianH
23-Mar-2008
[9574]
Will you only be replacing literal values, or doing general pattern 
replacement?
[unknown: 5]
23-Mar-2008
[9575]
any occurrence even in embedded series
BrianH
23-Mar-2008
[9576]
I got that :) I was wondering what kind of things you were searching 
for, to be replaced. Just literal values? Blocks?
[unknown: 5]
23-Mar-2008
[9577]
practically anything
BrianH
23-Mar-2008
[9578]
Interesting. How do you check for equality? Do you go by reference 
or structural equivalence?
[unknown: 5]
23-Mar-2008
[9579x3]
well that is where it gets a little of a concern.  Currently, I only 
check for equal?
>> b: [[1] [[[1]]] [1]]
== [[1] [[[1]]] [1]]
>> replace-all b [1] [2]
== [2]
>> b
== [[2] [[[2]]] [2]]
Can also do this:

>> b: [[1] [[[1]]] [1]]
== [[1] [[[1]]] [1]]
>> replace-all b 1 2
== 2
>> b
== [[2] [[[2]]] [2]]
BrianH
23-Mar-2008
[9582]
That is structural equivalence. Nice.
[unknown: 5]
23-Mar-2008
[9583x2]
>> b: [[1] [[[1]]] [1]]
== [[1] [[[1]]] [1]]
>> replace-all [1] "1"
** Script Error: replace-all is missing its newval argument
** Near: replace-all [1] "1"
>> replace-all b [1] "1"
== "1"
>> b
== ["1" [["1"]] "1"]
It works very well
BrianH
23-Mar-2008
[9585x2]
I would call it replace-deep, but cool.
Is it recursive?
[unknown: 5]
23-Mar-2008
[9587x9]
yes
Doesn't take much
replace-all: func [series oldval newval /local sd][
        sub-ic?: func [sd][
            forall sd [
                either equal? first sd oldval [
                    poke sd 1 newval
                ][
                    if series? first sd [sub-ic? first sd]
                ]
            ]
        ]
        sub-ic? series
    ]
was written for a particular use I had but not for general use.  
It will have some limitations to be a mezzanine
It was built rapidly off of another function that I built in TRETBASE.
If you see a series it doesn't work on let me know.
I see some errors in it already in the code that I should patch real 
quick
Here you go:
replace-all: func [series oldval newval /local sub-ic][
        sub-ic: func [sd][
            forall sd [
                either equal? first sd oldval [
                    poke sd 1 newval
                ][
                    if series? first sd [sub-ic first sd]
                ]
            ]
        ]
        sub-ic series
    ]
BrianH
23-Mar-2008
[9596x2]
Not bad. You use an inner function for the recursion, which should 
allow you to go to greater recursion depth before running out of 
stack space. I'd change the series? to any-block?, and the EITHER 
IF to a CASE, and the FORALL to a WHILE, and add type specs to the 
outer function, and change /local sd to /local sub-ic?, but otherwise 
good stuff.
Sorry, I wrote most of that before you posted your fixed version.