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
[9600]
Be sure to change your oldval and newval references to get-words 
for safety.
[unknown: 5]
23-Mar-2008
[9601x2]
Not sure I follow you.
Oh so it doesn't evaluate them you mean.
BrianH
23-Mar-2008
[9603]
either equal? first sd :oldval [
                    poke sd 1 :newval
[unknown: 5]
23-Mar-2008
[9604x6]
Yeah good point
Did i spark your interest for changing the replace function?
If so I suggest you keep the replace function and make this an entirely 
different replace function.  Call it replace-deep if you like.
Then just cut out out the /all from your current replace function 
and leave as is.
The reason is that I believe this will be more tasking on the stats/evals 
then replace is by far.
By the way that recursion method with the function inside the function 
is the only way I found to get round most of those stack errors you 
mentioned.
BrianH
23-Mar-2008
[9610]
Have you seen the replace function? We are getting to the point of 
diminishing returns on new features - too much complexity overhead. 
As it is, we are going to have to use APPLY in the R3 version just 
to add another option.
[unknown: 5]
23-Mar-2008
[9611]
No I haven't really paid much attention to it.  i know there was 
some discussion on the 2.7.6 discussions but i haven't followed R3 
development much at all.
BrianH
23-Mar-2008
[9612]
Do source replace - it's a good way to learn some interesting optimization 
techniques.
[unknown: 5]
23-Mar-2008
[9613]
is it the same in 2.7.6 as it is in 2.7.5?  I'm currently using 2.7.5.
BrianH
23-Mar-2008
[9614]
No, it really isn't. The 2.7.6 REPLACE was one of the backports, 
as was EXTRACT.
[unknown: 5]
23-Mar-2008
[9615x2]
Extract is in 2.7.5 also which is the one I was using.  Maybe that 
is why we are on different pages on that issue.
I'll check them out later.
BrianH
23-Mar-2008
[9617]
I didn't realize that you weren't using 2.7.6. I wrote REPLACE and 
EXTRACT in that release.
[unknown: 5]
23-Mar-2008
[9618x3]
oh - lol.
replace-all: func [series oldval newval /local sub-ic][
        sub-ic: func [sd][
            while [not tail? sd ][  
                either equal? first sd :oldval [
                    poke sd 1 :newval
                ][
                    if series? first sd [sub-ic first sd]
                ]
                sd: next sd
            ]
        ]
        sub-ic series
        series
    ]
>> replace-all b 2 1
== [[1] [[[1]]] [1]]
>> stats/evals
== [219 105 47]
BrianH
23-Mar-2008
[9621]
Do you really want to do this:
>> replace-all ["1"] 1 2
== ["2"]
Otherwise, change series? to any-block?
[unknown: 5]
23-Mar-2008
[9622]
Actually, that is exactly what I want
BrianH
23-Mar-2008
[9623x2]
replace-all: func [series oldval newval /local sub-ic][
        sub-ic: func [sd][
            while [not tail? sd ][  
                case [
                    equal? first sd :oldval [poke sd 1 :newval]
                    series? first sd [sub-ic first sd]
                ]
                sd: next sd
            ]
        ]
        sub-ic series
        series
    ]
CASE is faster than 2 comparisons with EITHER or IF.
[unknown: 5]
23-Mar-2008
[9625]
I recall you saying that before I never really checked it out.
BrianH
23-Mar-2008
[9626]
I profile code patterns to see which is faster.
[unknown: 5]
23-Mar-2008
[9627x3]
I think your case is messed up
I think I had that if for a reason but not sure why
in the case of mine both conditions will not be true whereas in your 
case arrangment both can can't they?
BrianH
23-Mar-2008
[9630]
Not unless you use case/all. Did you have /case as an option to your 
function at some point?
[unknown: 5]
23-Mar-2008
[9631x2]
all yeah I always forget that.
Keep thinking of like switch when I see case and I use case often.
BrianH
23-Mar-2008
[9633]
It's more like cond from Lisp.
[unknown: 5]
23-Mar-2008
[9634]
yeah I never used another language other than REBOL so I wouldn't 
know.
BrianH
23-Mar-2008
[9635]
Wow. I've never heard that before.
[unknown: 5]
23-Mar-2008
[9636x3]
lol - I'm just a hobbiest with REBOL.
I have no programming education.  Had to self teach me this stuff.
That is why when you use a lot of programming terms I'm lost.
BrianH
23-Mar-2008
[9639]
I'm self-taught too, but after more than 20 years you pick up some 
stuff :)
[unknown: 5]
23-Mar-2008
[9640x6]
I think that replace function is good Brian.  I would push for that 
to be a mezzanine at this point.
:-)
the reason I like it as series instead of any-block is for using 
it on long strings.
>> str: "this is just a test of replace-all"
== "this is just a test of replace-all"
>> replace-all str #"t" #"d"
== "dhis is jusd a desd of replace-all"
The case did cut it down a bit on the evals:
>> replace-all b 1 2
== [[2] [[[2]]] [2]]
>> stats/evals
== [209 100 42]
I would say that is one heck of a useful function
BrianH
23-Mar-2008
[9646]
I've been using timblk to profile, not stats. How useful have you 
found stats to be?
[unknown: 5]
23-Mar-2008
[9647x3]
its pretty useful.  Btiffin mentioned timblk also. I will have to 
look for it sometime.
replace-all: func [
    "Replaces all occurences of old value with new value"
    series "Series containing values to replace"
    oldval "Value to be replaced"
    newval "New value to replace old value"
    /local subf
    ][
        subf: func [sd][
            while [not tail? sd ][  
                case [
                    equal? first sd :oldval [poke sd 1 :newval]
                    series? first sd [subf first sd]
                ]
                sd: next sd
            ]
        ]
        subf series
        series
    ]
same function just commented a bit and changed sub-ic to just subf 
meaning subfunction