1. Phix vs OE syntax // switch
- Posted by _tom (admin) Apr 19, 2017
- 1476 views
[not a rant against Phix, because Phix switch "works" and ⵚE switch "works sometimes"]
[ observation, when ⵚE switch "does not work" using the Interpreter, the Translated version can work! ]
ⵚE follows this essential pattern:
for ... do ... end for while ... do ... end while switch ... do ... end switch
Phix sample
integer showprogress = 1 integer j = 0 for i=1 to 4 do switch i case 1,2: if showprogress then puts(1,"i is 1 or 2\n") end if j += i case 3: case 4: if showprogress then puts(1,"i is 3 or 4\n") end if j += i end switch end for if j!=10 then ?9/0 end if /* i is 1 or 2 i is 1 or 2 i is 3 or 4 i is 3 or 4 */
Phix has:
- invisible syntax
- introduced punctuation
This syntax does not follow established syntax conventions
ⵚE sample
integer showprogress = 1 integer j = 0 for i=1 to 4 do switch i do case 1,2 then if showprogress then puts(1,"i is 1 or 2\n") end if j += i case 3 then case 4 then if showprogress then puts(1,"i is 3 or 4\n") end if j += i end switch end for puts(1, "\n----------------------------\n") ? j if j!=10 then ?9/0 end if /* i is 1 or 2 i is 1 or 2 i is 3 or 4 ---------------------------- 7 attempt to divide by 0 */
ⵚE is consistent:
- "do" follows "switch"
- "then" instead of ":"
ⵚE follows established conventions
Yes, ⵚE is verbose. Yes, ⵚE is Friendly because syntax is uniform and follows simple rules.
_tom
2. Re: Phix vs OE syntax // switch
- Posted by petelomax Apr 19, 2017
- 1432 views
Phix fully supports that OE syntax, with the same results as the Phix-only version above (ie j ends up 10).
In the Phix switch statement, do is optional and ":" and "then" are interchangeable.
Phix allows several such syntax variations, mainly to ease the translation of C into Phix, the most notable of which is the optional ; statement separator.
Just last month I also added support for the ORAC-isms int[eger], seq[uence], ~s for length(s), s.i for s[i], and s[i to j] for s[i..j] - you are not obliged to use them. (set ORAC to 0 if no likely)
If you think it would help, I could easily add "--/**/with strict_oe_syntax" or somesuch, on the understanding it would not cover sequence ops and equal/compare use, or implicit function discard (etc).
Pete
3. Re: Phix vs OE syntax // switch
- Posted by _tom (admin) Apr 19, 2017
- 1455 views
Nice work.
What is needed now is some unified documentation. I am beginning to think in terms of Euphoria Languages rather than Euphoria, OpenEuphoria, Phix. The idea is to merge OE and Phix docs, or at least insert cross reverences.
_tom