Re: [OE vs Phix] assigning atom to a slice is different

new topic     » goto parent     » topic index » view thread      » older message » newer message

Sorry, I forgot that self-hosting is broken on linux (or rather libc.so.6/system is throwing error code 32512 which makes no sense). I've rebuilt and uploaded the compiler, so the following should do the trick:

wget http://phix.x10.mx/p32 
mv p32 phix/p 

and I have now pushed that change to the repository.

--string s = "fed"  
seq s = "fed"  
s[2..2] = "ee"    -- s is now "feed" -- given  
  
seq p = "ee"  
s[2] = p          -- s is now "'f',"ee",'d'" ?  
--type check failure, s is {102,"ee",101,100} when s is string 
?s                -- s is now {'f',"ee",'e','d'} 
  
s[2..3] = "12"    -- s is now "f12" ?  
?s                -- s is now {'f','1','2','d'} 
s[2..-2] = "12"   -- s is now "f21d" ?  
?s                -- s is now {'f','1','2','d'} 

Some operations on a string must auto-expand it to a dword-sequence; obviously that proved necessary for compatibility reasons. There is no such thing as an auto-compact.

Note that you can do pretty much anything with {'f','1','2','d'} that you can do with "f12d", obviously apart from storing it in a string variable, and compare({'f','1','2','d'},"f12d") yields 0 (equal), however they are quite different internally.

s[2..-2] is exactly the same as s[2..3] for a length 4 sequence, it does not reverse the slice being copied, dunno what made you think that.

A real-world example of this being useful could be a template letter containing "Dear [name],\nThank you for..." and you want to put the actual name in there.

For some online docs see http://phix.x10.mx/docs/html/slices.htm

Ultimately s[i..j] = rep is just a shorthand for s = s[1..i-1] & rep & s[j+1..$]
If it cannot do it in situ (eg because the lengths differ) then that is pretty much what it does internally, not significantly more difficult than what say a &= b has to do.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu