Author Topic: Phix Introduction  (Read 8804 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Phix Introduction
« 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)
  • A remarkably simple, yet flexible and powerful language definition that is easy to learn and use.
  • A high-performance interpreter/compiler much faster than most.
  • Fully managed dynamic data storage with no requirement to allocate or free memory. Variables can grow or shrink to any size without any manual housekeeping.
  • Extensive run-time checking for: out-of-bounds subscripts, uninitialized variables, bad parameter and variable assignments and many more. There are no mysterious machine exceptions -- you always get a full English description of any problem that occurs within your program at run-time, with the exact source line it occurs on, along with a full call-stack listing and a dump of all of your variable values. Programs can be debugged quickly, easily, and more thoroughly.
  • A source level debugger allows execution of programs line-by-line. Tracing can begin (or end) on any line or for any condition, under full programmer control.
  • A built-in execution profiler identifies which lines of code take up the highest percentage of execution time, or are executed the most often.
  • Features of the underlying hardware are usually hidden. Programs are not typically aware of word-lengths, bit-representations, byte-order etc.
  • However, phix also satisfies anyone with a deeper curiosity. There is no hidden wall between the language and the operating system to fully understand how things actually work. Phix can create low-level listing files which show the exact addresses and assembly instructions generated, and also includes a program (filedump.exw) that shows every bit and byte in full detail (within reason, for example icons and other such data are shown in raw hex), for Windows PE, Linux ELF, and other format files.
  • Self-hosted so there is no need to know another language, or obtain any other development tools, to enhance or fix the language itself. You can easily download, install, and recompile phix in less than two minutes! (See the short webcast at http://phix.is-great.org/tutorial.php, and also Recommended Tools.)
  • The Edita programmers editor is freely available, and written in phix with everything you might expect, including multiple and user-definable syntax colouring, multilingual support, intellisense, autocompletion, code folding, integrated help, window painter, full source, and more.
  • Standalone executables can be created simply by adding a "-c" flag to the normal interpret command (or via Ctrl F5 if using Edita). (The detailed assembly listing mentioned above is likewise just a "-d".) There are no complicated compiler options to remember and there is no separate linking phase. A simple "format" directive in the source allows for easy cross-compilation to any other supported system.
  • Phix programs are naturally generic. The example program shows a single routine that will sort any type of data -- integers, floating-point numbers, strings etc. Phix achieves many of the benefits of object-oriented programming, yet in a much simpler way.

Phix Bitbucker Project Repository

Phix Tutorial

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"} .
« Last Edit: November 20, 2017, 10:46:14 PM by John »

Offline AlyssonR

  • Advocate
  • Posts: 126
Re: Phix Introduction
« Reply #1 on: November 21, 2017, 07:01:15 AM »
Interesting - not a language I've seen before.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Phix Introduction
« Reply #2 on: November 21, 2017, 01:24:09 PM »
Discovered Phix on the IUP mailing list. It seems to have close ties with Euphoria.
« Last Edit: November 22, 2017, 08:52:04 PM by John »

Offline petelomax

  • BASIC Developer
  • Posts: 9
  • Author of Phix
    • The Phix Programming Language
Re: Phix Introduction
« Reply #3 on: November 25, 2017, 04:14:11 PM »
Hello, Pete here (the author of Phix) - any questions let me know.

Offline petelomax

  • BASIC Developer
  • Posts: 9
  • Author of Phix
    • The Phix Programming Language
Re: Phix Introduction
« Reply #4 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


Offline Gemino Smothers

  • BASIC Developer
  • Posts: 24
    • Lucid Apogee
Re: Phix Introduction
« Reply #5 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!

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Phix Introduction
« Reply #6 on: July 07, 2023, 06:01:01 PM »
Maintaining a BASIC can bring much joy.