AllBASIC

BASIC Developer & Support Resources => Interpreters => Phix => Topic started by: John on November 20, 2017, 09:44:36 PM

Title: Phix Introduction
Post by: John on November 20, 2017, 09:44:36 PM
Introduction - Phix is Pete’s Self Hosted Hybrid Interpreter/Compiler


Phix has several advantages over other programming languages:  (Self compiling is a bonus)

Phix Bitbucker Project Repository (https://bitbucket.org/petelomax/phix)

Phix Tutorial (http://phix.x10.mx/tutorial.php)

Example Program
Code: [Select]
function merge_sort(sequence x)
-- put x into ascending order using a recursive merge sort
integer midpoint
sequence merged, first_half, second_half
     if length(x)<=1 then
         return x  -- trivial case
     end if
     midpoint = floor(length(x)/2)
     first_half = merge_sort(x[1..midpoint])
     second_half = merge_sort(x[midpoint+1..$])
     -- merge the two sorted halves into one
     merged = {}
     while length(first_half)>0
       and length(second_half)>0 do
         if first_half[1]<=second_half[1] then
             merged = append(merged, first_half[1])
             first_half = first_half[2..$]
         else
             merged = append(merged, second_half[1])
             second_half = second_half[2..$]
         end if
     end while
     -- result is the merged data plus any leftovers
     return merged & first_half & second_half
end function
sequence list = {9, 10, 3, 1, 4, 5, 8, 7, 6, 2}
     ? merge_sort(list)

The above example delares a function, a sequence, and then invokes the function and displays the results. It also demonstrates how sequences (flexible arrays) are the real powerhouse of phix.

The output from the program is:
    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

merge_sort() will just as easily sort {1.5, -9, 1e6, 100} or {"oranges", "apples", "bananas"} .
Title: Re: Phix Introduction
Post by: AlyssonR on November 21, 2017, 07:01:15 AM
Interesting - not a language I've seen before.
Title: Re: Phix Introduction
Post by: John on November 21, 2017, 01:24:09 PM
Discovered Phix on the IUP mailing list. It seems to have close ties with Euphoria.
Title: Re: Phix Introduction
Post by: petelomax on November 25, 2017, 04:14:11 PM
Hello, Pete here (the author of Phix) - any questions let me know.
Title: Re: Phix Introduction
Post by: petelomax on November 26, 2017, 03:43:10 AM
On Sun, 26/11/17, e-mail@johnspikowski.com <e-mail@johnspikowski.com> wrote:

Thanks Pete!
 Are you able to do COM/OLE with the Windows version?
 John
-----

Yes, but it's not easy. One thing I have done is translate

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776913

into builtins/fileopenN.ew which can be tested with demo/pGUI/filedlg.exw (and I have just edited that to put a sequence(res) check around the check_ansi(res[2]) call on line 68)

There is also EuCom, http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.ComLibrary but to be honest that may be slightly broken at the moment, though that does have more of the VARIANT style handling and it would no doubt progress a bit faster with someone on board willing to push things in the right direction - I've personally had relatively little experience with this stuff.

Regards,
Pete

Title: Re: Phix Introduction
Post by: Gemino Smothers on July 07, 2023, 09:36:30 AM
Phix looks like a great alternative to Java or Python.

I see Phix daily as I work on Rosetta Code tasks. It's one of the simpler to read languages there and has helped me to understand/translate tasks as I look through various languages.

It's cool to see the author here in the BASIC community!
Title: Re: Phix Introduction
Post by: John on July 07, 2023, 06:01:01 PM
Maintaining a BASIC can bring much joy.