Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Extract applied to binary!

 [1/4] from: rudolf::meijer::telenet::be at: 16-Mar-2008 21:27


To quote change.txt included in the 2.7.6 SDK distribution: "Note that <w>EXTRACT now returns a series of the same type as the source series." This is technically true for binary series, but it still does not work as one should have the right to expect intuitively. Let us take a simple binary series, created by to-binary "1 2 3 ", thus #{312032203320}. One should expect <extract #{312032203320} 2> to result in #{313233} just like <extract 1 2 3 2> results in "123". However this is not the case: the result is #{343935303531}. This is because each element of a binary series is of type integer, and although the first element of #{312032203320} is 49, the result of <append #{} 49> is not #{31} but #{3439}, in other words 49 is implicitly converted to string! before the append. However, if one computes <copy/part #{312032203320} 1>, one gets #{31}, and <append #{} #{31}> yields #{31} as it should. In other words, in the source of extract, it suffices to replace <pick block pos> by <copy/part at block pos 1>, in order to obtain a result which is similar to that for strings. What do you think? Rudolf W. MEIJER mailto:rudolf.meijer-telenet.be http://users.telenet.be/rwmeijer/

 [2/4] from: gregg:pointillistic at: 16-Mar-2008 22:41


Hi Rudolf, That's a good catch on the behavior. Brian Hawley will probably chime in on this. These subtle behaviors--forming values--are helpful most of the time. Obviously, in this case, they're not. -- Gregg

 [3/4] from: rudolf:meijer:telenet:be at: 17-Mar-2008 8:03


Hi I just discovered that in REBOL 3 (2.99 rather :-) the behaviour is different: the type of an element picked from a binary series is char! rather than integer! and the extract (therefore ?!) actually works as expected. If this can be retrofitted in 2.7 it would indeed hlp. Rudolf

 [4/4] from: santilli::gabriele::gmail::com at: 17-Mar-2008 11:32


On Mon, Mar 17, 2008 at 8:03 AM, Rudolf W. MEIJER <rudolf.meijer-telenet.be> wrote:
> I just discovered that in REBOL 3 (2.99 rather :-) the behaviour is > different: the type of an element picked from a binary series is char! > rather than integer!
This is very likely to change with the next release supporting Unicode. Hopefully we'll find a good compromise... Regards, Gabriele.