1. [phix] about 'string' design?

string str1 = "hello" 
string str2 = { 'h','e','l','l','o' } 
string str3 = {104,101,108,108,111} 

str2 and str3 give a type-check error

but

? str1 =  { 'h','e','l','l','o' }  // true 
? str1 = {104,101,108,108,111}     // true 

What is the language design choice behind this behavior?

be well
_tom

new topic     » topic index » view message » categorize

2. Re: [phix] about 'string' design?

Compatibility. Many programs, including my own Edita, which was originally Eu, would regularly make dword-sequences out of or instead of strings, especially by starting with {} instead of "", and then expect things like puts(1,{'h','e','l','l','o'}) to work. Same with find(), match(), and as you say, =, etc. So the situation is that if you declare a variable as a sequence, then strings and "flat" dword-sequences work identically, however if you declare it as a string then you are effectively saying the 75% or 87.5% space saving that strings offer is actually important, as well as a few other ways that the stricter typechecking is helpful. The compatibility side has been watered down a little since the early days, but it is unlikley to ever fully go away.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu