You forgot to copy the data_to_find binary value. Replace the

probe data_to_find: #{ACDC}

with data_to_find: copy #{ACDC}

The append changes the series!... an example:

>> a: [ b: #{ACDC} append b #{a0} ]
== [b: #{ACDC} append b #{A0}]
>> do a
== #{ACDCA0}
>> a
== [b: #{ACDCA0} append b #{A0}]
>>

If you do not copy the series your will change your own code.

>> a: [ b: #{ACDC} append copy b #{a0} ]
== [b: #{ACDC} append copy b #{A0}]
>> do a
== #{ACDCA0}
>> a
== [b: #{ACDC} append copy b #{A0}]
>>

That should fix it...

Daan Oosterveld

[EMAIL PROTECTED] schreef:

> Hej Andrew,
>
> Thanks for the hints, I changed according to your suggestions.
>
> But the function still gets incorrect data, any other ideas?
>
> ---
> find_stuff2: func ["Find stuff in data_block"] [
>
>   tail_data: make string! 0
>   tail_data: ask "what data do you want to find after ACDC? "
>   probe data_to_find: make string! 0
>   probe clear data_to_find
>   probe data_to_find: #{ACDC}
>   probe append data_to_find do rejoin ["#{" tail_data "}"]
>
>   result: make block! 0
>   clear result
>   foreach data data_block [
>     if find data data_to_find [
>       append result data
>     ]
>   ]
> print rejoin ["Found " length? result " containing " data_to_find]
> ]
>
> But I still get the same fault:
>
> >> find_stuff2
> what data do you want to find after ACDC? 01
> ""
> ""
> #{ACDC}
> #{ACDC01}
> Found 2 containing #{ACDC01}
> >> find_stuff2
> what data do you want to find after ACDC? 01
> ""
> ""
> #{ACDC01}
> #{ACDC0101}
> Found 0 containing #{ACDC0101}
>
> Brgds /Micael
> -----Ursprungligt meddelande-----
> Fr�n: Andrew Martin [mailto:[EMAIL PROTECTED]]
> Skickat: den 10 november 2000 23:41
> Till: [EMAIL PROTECTED]
> �mne: [REBOL] Re: Func, why does it remeber previous data?
>
> >   tail_data: ""
>
> Use:
>         tail_data: make string! 0
>     instead.
>
> Think of ":" as being:
>         Set the word to the left to _POINT_ to the string at the right.
>     So this:
>         tail_data: ""
>     actually means:
>         Set the word "tail_data" to this particular empty string. It's like
> assigning a pointer in C/C++, OK?
>
> The same thing applies here:
> >   result: []
>
>     Use:
>         result: make block! 0
>     instead.
>
> Andrew Martin
> ICQ: 26227169
> http://members.nbci.com/AndrewMartin/
> -><-
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, November 11, 2000 10:10 AM
> Subject: [REBOL] Func, why does it remeber previous data?
>
> > Hi all,
> >
> > I am playing around with a function that search through a block containing
> > binary values.
> > My function searches through the block for the binary #{ACDC} plus #{??}
> >
> > The problem I encounter is when I run the function multiple times, the
> > binary variable "data_to_find" remembers old data from the same function,
> > even if I clear it.
> >
> > Can someone please explain this behaviour and give me some hints of how to
> > get around it?
> >
> > Here's the script:
> > -----------------------------------------------------------
> > find_stuff: func ["Find stuff in data_block"] [
> >
> >   tail_data: ""
> >   tail_data: ask "what data do you want to find after ACDC? "
> >   probe data_to_find: ""
> >   probe clear data_to_find
> >   probe data_to_find: #{ACDC}
> >   probe append data_to_find do rejoin ["#{" tail_data "}"]
> >
> >   result: []
> >   clear result
> >   foreach data data_block [
> >     if find data data_to_find [
> >       append result data
> >     ]
> >   ]
> > print rejoin ["Found " length? result " containing " data_to_find]
> > ]
> > ------------------------------------------------------------
> > Here's an example of running the script:
> > ------------------------------------------------------------
> > >> data_block: [#{ACDC01} #{ACDC02} #{ACDC03} #{ACDC01} #{ACDC02}]
> > == [#{ACDC01} #{ACDC02} #{ACDC03} #{ACDC01} #{ACDC02}]
> >
> > >> find_stuff
> > what data do you want to find after ACDC? 01
> > ""
> > ""
> > #{ACDC}
> > #{ACDC01}
> > Found 2 containing #{ACDC01}
> >
> > >> find_stuff
> > what data do you want to find after ACDC? 01
> > ""
> > ""
> > #{ACDC01}                      <----- Where does 01 come from?
> > #{ACDC0101}
> > Found 0 containing #{ACDC0101}
> > >> find_stuff
> > what data do you want to find after ACDC? 02
> > ""
> > ""
> > #{ACDC0101}                    <----- Where does 0101 come from?
> > #{ACDC010102}
> > Found 0 containing #{ACDC010102}
> > >>
> > -----------------------------------------------------------
> > Brgds /Micael
> > --
> > To unsubscribe from this list, please send an email to
> > [EMAIL PROTECTED] with "unsubscribe" in the
> > subject, without the quotes.
> >
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to