1. [Phix] ? operator; string behavior
- Posted by _tom (admin) Oct 31, 2017
- 1362 views
In Phix, the ability of question_mark ? being able to output text and numbers is really handy:
Statement | Phix output | OE output |
---|---|---|
? 'A' | 65 | 65 |
? 'A' + 32 | 97 | 97 |
? 'A' & 'a' | "Aa" | {65,97} |
? 65 & 97 | "Aa" | {65,97} |
? 65 | 65 | 65 |
? {65} | {65} | {65} |
? "A" | "A" | {65} |
? "A" + 32 | "a" | 97 |
? {65} + 32 | {97} | {97} |
? 65 + 32 | 97 | 97 |
? 65 & 97 | "Aa" | {65,97} |
In Phix, single_quote ' delimiters sometimes make a number and sometimes a character. Any sometimes syntax is disturbing.
Phix
object x = { 'h','e','l','l','o' } ? x puts(1, x) printf(1, "%s", {x} ) /* {104,101,108,108,111} ello?helloPress any key... */
- The 'h' is not output using the ? operator.
- And, where does the extra '?' come from?
_tom
2. Re: [Phix] ? operator; string behavior
- Posted by petelomax Oct 31, 2017
- 1340 views
You found a bug! (actually in puts not ?, btw)
In builtins/VM/pfileioN.e, line 5195:
[ELF64] --%rax System call %rdi %rsi %rdx %rcx %r8 %r9 --1 sys_write unsigned int fd const char *buf size_t count mov rax,1 -- sys_write -- rdi already set -- fd --31/10/17 (thanks to tom for finding this) -- mov rcx,rsp -- buffer (==rdx btw) mov rsi,rsp -- buffer (==rdx btw) mov rdx,1 -- count syscall
Despite having copied the api out for reference, I completely ignored it and set rcx instead of rsi, which just happens to be always pointing at the next character.
Obviously, after that 2-character edit, just run ".\p -c p" and it should be fixed.
Thanks, Pete
3. Re: [Phix] ? operator; string behavior
- Posted by _tom (admin) Nov 06, 2017
- 1272 views
Testing Phix and WEE.
Irv's patch now makes WEE work in utf8: WEE, puts, terminal, office, and internet now all work in utf8.
Pete's Phix patch makes ? operator behave.
Phix ? operator
- ? string of plain-text characters is output as text
- ? string of utf8 characters is output as numbers
? "hello" -- PLAIN TEXT --> "hello" ? "ΕίČ░☼□" -- UTF8 TEXT -->{195,133,195,159,196,140,226,150,145,226,152,188,226,150,161}
- puts will output utf8 text
puts(1,"ΕίČ░☼□") --> ΕίČ░☼□
- ? will output plain-text in its literal form
- puts outputs text; control characters are active
-- literal (control characters not active) ? "--- \n ---" /* "--- \n" ---" */ -- control characters active puts(1, "--- \n ---" ) /* --- --- */
I now have WEE able to output utf8 to a terminal.
The Phix ? operator does not output utf8 text to a terminal.
Should the ? operator output utf8 strings?
_tom
4. Re: [Phix] ? operator; string behavior
- Posted by petelomax Nov 07, 2017
- 1205 views
There is a c>#7E on line 31 in function allascii in builtins\VM\psprintN.e that you might want to change to c>#FF
Should the ? operator output utf8 strings?
Can't say that has ever occurred to me. I generally view ? as a quick-and-dirty diagnostic that usually gets "it" (/the mind-reading thing) wrong anyway - eg this week I had a {3,4} that was not so helpful, so I whipped up a quick routine to show it as {PRE_SIB,POST_SIB}, somewhat more meaningful to me at the time. I might estimate that about 1 in 5 times I immediately replace a ? with pp(), printf(), or whatever, so I guess I have become pretty immune to any shortcomings. Another classic for me is ?ch --> printf(1,"%c\n",ch) or perhaps the ?""&ch or ?ch&"" trick.
No matter, the above change should do you proud anyways, since (I think) utf8 deliberately avoids bytes <#32.
Pete
5. Re: [Phix] ? operator; string behavior
- Posted by _tom (admin) Nov 07, 2017
- 1167 views
The automagic is in the Phix 'print'
print(1, "cat") --> "cat" puts(1,"ΕίČ░☼□" ) --> "ΕίČ░☼□" print(1, "ΕίČ░☼□" ) --> {195,133,195,159,196,140,226,150,145,226,152,188,226,150,161}
This makes Phix 'print' fundamentally different from OE 'print'.
Maybe Phix 'print' should have been named 'write' (because it is automagic).
_tom
6. Re: [Phix] ? operator; string behavior
- Posted by petelomax Nov 07, 2017
- 1169 views
print(1, "ΕίČ░☼□" ) --> {195,133,195,159,196,140,226,150,145,226,152,188,226,150,161}
With the above change in place it matches the puts.
This makes Phix 'print' fundamentally different from OE 'print'.
Well, yeah, OE does not have a string type... They have always been different and always will be.
However, the documentation of print() does need updating to reflect that.