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

[REBOL] Re: Curious 'rejoin behavior

From: joel:neely:fedex at: 30-May-2001 17:31

Hi, Scott, You understand it, you just don't know that you do! ;-) GS Jones wrote:
> I was working through some xml to rebol conversions, and I > noticed what seems to be curious behavior on the part of > 'rejoin. I suspect that this is a bug, but maybe I have > misunderstood the behavior of this word. > > example: > > price: 2 > rejoin [ <bid> price </bid> ] ; returns: <bid2</bid>> > ; shouldn't it be: <bid>2</bid> > > Bug or have I misunderstood some fundamental property of > 'rejoin? > >From this experiment we conclude that the result of REJOIN
has the same type as the first value in the block.
>> rejoin [[1 2 3] 4 5 [6 7 8]]
== [1 2 3 4 5 [6 7 8]]
>> rejoin ["1 2 3" 4 5 [6 7 8]]
== "1 2 3456 7 8" Several of the interesting data types in REBOL may be viewed as variations of string, since they can be handled as series of characters:
>> series? <tag>
== true
>> series? http://foo.com/
== true
>> any-string? <tag>
== true
>> any-string? http://foo.com/
== true
>> any-string? [joel--neely--fedex--com]
== true This can be convenient if we need to manipulate those values:
>> urlhost: http://foo.com/
== http://foo.com/
>> urlpath: "some/random/path"
== "some/random/path"
>> urlfile: %bletch.html
== %bletch.html
>> type? urlhost
== url!
>> type? urlpath
== string!
>> type? urlfile
== file!
>> rejoin [urlhost urlpath urlfile]
== http://foo.com/some/random/pathbletch.html
>> type? rejoin [urlhost urlpath urlfile]
== url! Since a tag is a "string-like" series, REJOIN operates on it in a "string-like" way, but retains the type of tag! for the result.
>> opentag: <bid>
== <bid>
>> type? opentag
== tag!
>> first opentag
== #"b"
>> second opentag
== #"i"
>> third opentag
== #"d" You were bitten by the negative consequence of this implicit stringization of the tag type. Here's an example of how it can be beneficial:
>> type? probe rejoin [
opentag { attr0="value0"} { attr1="value1"} ] <bid attr0="value0" attr1="value1"> == tag! One way to get your intended behavior (at least, I assume I know what you wanted ;-) is to consider the following:
>> price: 2
== 2
>> reduce [ <bid> price </bid> ]
== [<bid> 2 </bid>]
>> to-string reduce [ <bid> price </bid> ]
== "<bid>2</bid>" Hope this helps! -jn- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com