1. Starting indeces at 0 in Phix
- Posted by begin Oct 25, 2021
- 901 views
Well I don't want to start a flame war, but would it be possible to have a switch that would allow to start at 0 instead of 1 when counting sequences etc.? I would make it a lot easier to port C source code. Thanx
2. Re: Starting indeces at 0 in Phix
- Posted by ChrisB (moderator) Oct 27, 2021
- 803 views
Well that sounds like it should be really easy to implement, why's it not been done before??
Chris
3. Re: Starting indeces at 0 in Phix
- Posted by begin Oct 28, 2021
- 790 views
I wondered about that too. It would make the porting of algo from C to Phix a lot easier. We are now always fighting with programs like loees/lowest and other statistics. One could make a switch like some basic compilers did in the past to have indeced start at 0 etc. Starting at 1 is source of many errors.
4. Re: Starting indeces at 0 in Phix
- Posted by petelomax Nov 07, 2021
- 634 views
That would be a mammoth undertaking and a monumental mistake to even try.
As you probably know, pwa/p2js transpiles Phix code to JavaScript.
What you probably did not know is that it is also supposed to be able to transpile the generated JavaScript back into working Phix code.
From that point it might not be utterly ridiculous to transpile [nb plain] C code into (almost) working Phix code.
Obviously the aim is not and never will be to "work out of the box", but instead to "reduce tedious manual effort".
It would, for instance, be perfectly reasonable for such a transpiler to force you to comment out any bits it does not understand, and retry.
Of course pretty much all included C libs would be out, so don't be expecting (say) parseXAML() calls to work!
To get the ball rolling, what you need to do is find and post a short C sample along with the nearest manually ported line-for-line working Phix code you can muster.
In the specific case of 0==>1 based indexes I would expect the latter code to contain several otherwise unnecessary "+1]", and
suppress any natural instinct to optimise, invoke builtins, or replace anything with a standard idiom.