The Phix Programming Language (original) (raw)
"I don't want to die in a language I can't understand."
- Jorge Luis Borges
Latest version: 1.0.5
Release date: 1st June 2024
Price: Free. No nags and No expiry date.
Source code: Incuded.
Self Hosted: No other tools required to modify/rebuild Phix.
- -- Phix has just five builtin data types
--
-- <======== object =========>
-- | |
-- +-atom +-sequence
-- | |
-- +-integer +-string
-- - -- Phix is simple
puts(1, "Hello, World!")
-- and can be interpreted or compiled:
$ p hello
Hello, World!
$ p -c hello
Hello, World! - -- Phix is multi-platform
C:\Phix> p hello
Hello, World!
~/phix$ .\p hello
Hello, World!
?iff(platform()=WINDOWS?"Windows":"Linux") - -- user-defined types made simple
type pair(object p)
return sequence(p) and length(p)=2
end type
pair p1 = {2,3} -- ok
pair p2 = {2,4,6} -- fails
p1 &= 0 -- fails - -- line comments
/*
multiline comments
/* nestable */
*/ - -- naturally polymorphic
?sort({1, 1.5, "oranges", -9, 1e300, 100, "apples"})
Output:
{-9,1,1.5,100,1e+300,"apples","oranges"} - -- one difference worth learning
sequence s1 = {1,2,3}, s2 = {4,5,6}
?s1&s2
?append(s1,s2)
Output:
{1,2,3,4,5,6}
{1,2,3,{4,5,6}} - -- negative subscripts are permitted
sequence s = tagset(6) ?s
s[-2..-1] = {-2,-1} ?s
--s[5..6] = {-2,-1} -- equivalent
Output:
{1,2,3,4,5,6}
{1,2,3,4,-2,-1} - -- fully mutable strings
string this = "feed"
string that = this -- both=="feed"
that[2..3] = "oo" -- that:="food"
this[1] = 'n' -- this:="need"
?{this,that}
Output:
{"need","food"} - -- variable length slice substitution
string s = "food" ?s
s[2..3] = "e" ?s
s[2..1] = "east" ?s
Output:
"food"
"fed"
"feasted" - -- Phix comes with batteries included...
include builtins\timedate.e
set_timedate_formats({"h:m:s"})
timedate start = parse_date_string("10:37:15"),
ended = parse_date_string("12:38:14")
?elapsed(timedate_diff(start,ended))
Output:
"2 hours and 59s"
- -- associative arrays aka dictionaries
setd("one",1)
setd(2,"duo")
?getd("one")
?getd(2)
Output:
1
"duo" - -- exception handling
try
integer i = 1/0
catch e
?e[E_USER]
end try
puts(1,"still running...\n")
Output:
"attempt to divide by 0"
still running... - -- regular expressions
include builtins\regex.e
?gsub(\ba\b
,"I am a string","another")
Output:
"I am another string"
Phix is Pete’s Self Hosted Hybrid Interpreter/Compiler pshhic was not the best of acronyms, plus phiX is the name of the first ever manmade lifeform artifically created from scratch in a laboratory, which seems rather appropriate for a self-hosted compiler
Aims:
- Create an easy to use programming language which is also easy to modify and maintain.
- Reject the premise that things must be tortuously complicated and difficult and confusing to make them flexible and powerful.
- Bug location must be made as easy as possible. If as some studies suggest up to 90% of effort is actually spent fixing bugs, it follows that the toolchain should be strongly focused on the expediency with which bugs can be located and fixed - at least those in otherwise well written code; obviously anything difficult to understand in the first place will more than likely prove at least as tricky the second time round, should it go wrong.
In Phix, all errors, both compile-time and run-time, are human-readable and indicate the precise file and line where they happened, and Edita jumps right there. - Allow the programmer to focus on solving the problem, rather than solving the solution.
- Terse may at first seem nice, but properly readable and easy to understand code is better.
Why Phix?
There are hundreds of programming languages, by which I probably mean tens of thousands...
- Single installation with zero dependencies, at least on Windows, though on Linux you’ll probably want IUP1
- Same code runs on Windows, Linux, and in a browser (done before, I know, just not imnsho anywhere near this well).
- Knowing that you (probably) could (quickly) modify the compiler(/interpreter/transpiler) should you need to2.
- Hundreds of examples, thousands of contributions, and 100% completion on rosettacode.
- Quality documentation (though I guess you should judge that one for yourself).
- Human readable error messages instead of cryptic nonsense, at least in 99.5% or more of cases.
- You wouldn’t mind a decent tool that at least appears to try to make your life a bit easier.
- And finally.. because giving it a decent spin should (bar IUP on Linux) be perfectly feasible in under 5 minutes.
(if you cannot get five examples to run in that time, I would genuninely like to hear why not)
1 I have indeed managed to get IUP going on Linux several times, but am simply not the best person to explain exactly how,
whereas in contrast I am perfectly happy to ship all the needed Windows 32/64 bit dlls in the standard distribution package.
Work has in fact also started on [yet another] cross platform GUI, just don’t hold your breath.
2 Phix was born out of frustration at waiting 18 months for a new release, only to find the problem was still there.
Why not?
If any of the following (meant to be mildly humorous) apply, then (sadly) Phix is probably not for you:
- Saving a few seconds when typing is far more important than saving several minutes when later reading it.
- Giving something a clear, meaningful, and intuitive name is somehow and for some reason exceptionally difficult.
- You pride yourself or otherwise rely on being the only person that can possibly maintain what you wrote.
- You firmly believe every line of code you write is utterly perfect and will never need modifying or debugging.
- If you have to struggle with 0-based indexes when programming in X, everyone else should have to, too.
- Using a particular design pattern or language feature is far more important than actually solving some problem.
- You simply cannot live without lambda expressions, closures, currying, monads, generators, iterators, etc.
- You strongly disagree that 'this' in JavaScript is nothing short of an unmitigated disaster, and refuse to let it go.
- You have no interest in making anything, ever, be it any tool or any of the processes involved, any easier.
- Being told the file name and line number on which an error occurred is only for amateurs and pathetic wimps.
- Down time while waiting for recompilation to finish is regarded as an important perk of the job.
- A one-liner is in your opinion always and without exception much better than an easier to read five-liner.
- Your preferred programmer’s editor does not support proper syntax colouring of Phix source code.
- Over-reliance on auto-completion, though I’ll grant you it is a nice feature to have.
- Actually understanding how a program works is a very strange and frankly rather weird concept.
- These days computers are so fast no-one cares if a program takes an extra twenty seconds to load. (You may wanna read that one again.)
Some Quotes I identify with:
“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”
- Antoine de Saint-Exupéry
“Simplicity is the ultimate sophistication.”
- Leonardo da Vinci (as commonly attributed, eg , but see )
“A language that doesn’t have everything is actually easier to program in than some that do.”
- Dennis M. Ritchie
“Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?”
- Edsger W. Dijkstra
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
- Brian W. Kernighan
“The readability of programs is immeasurably more important than their writeability.”
- C. A. R. Hoare
“Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction.”
- E. F. Schumacher
“If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.”
- Alfonso the Wise, 13th Century King of Castile
“Person who say it cannot be done should not interrupt person doing it.”
- Chinese Proverb