Simple is Better
 

"I don't want to die in a language I can't understand."
               - Jorge Luis Borges link



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"