[REBOL] Re: Help me Obi REB Kenobi! You're my only hope!
From: joel:neely:fedex at: 12-May-2002 14:28
Hi, again, Ed,
Ed Dana wrote:
> A couple quick follow-up questions, for my edification. :)
>
> Why can literals be surrounded by "" or {}. Is there a difference
> in how REBOL executes these strings?
>
> Just curious about the reason for this.
>
It's very handy to have multiple string delimiters, in case you
want to have strings that include delimiters themselves. For
example:
make-img: func [
src [string!]
/dim xy [pair!]
][
append
append <img> rejoin [{ src="} src {"}]
either dim [
rejoin [{ width="} xy/x {" height="} xy/y {"}]
][
""
]
]
which behaves as:
>> make-img "teeny.gif"
== <img src="teeny.gif">
>> make-img/dim "teeny.gif" 3x5
== <img src="teeny.gif" src="teeny.gif" width="3" height="5">
Niceties aside, the curly brackets are normally used for "longer"
strings and the quotation mark used for "shorter" strings.
>> glop: "123"
== "123"
>> append glop glop
== "123123"
>> append glop glop
== "123123123123"
>> append glop glop
== "123123123123123123123123"
>> append glop glop
== "123123123123123123123123123123123123123123123123"
>> append glop glop
== {12312312312312312312312312312312312312312312312312
3123123123123123123123123123123123123123123123}
But that's just a convention.
More importantly, the curly brackets can be used to create multi-
line strings easily:
>> {this
{ is
{ a
{ very
{ long
{ string
{ }
== {this
is
a
very
long
string
}
while quotation-mark-delimited strings must be on a single line:
>> "this
** Syntax Error: Missing " at "this
** Near: pick ["high" "low"] guess > secret
HTH!
-jn-
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]