# Learn to Phix Programming

## Is it Easy?

No. Programming is about solving problems. Solving some problems may be easy, but solving meaningful problems is hard work.

Yes. Simplify and add lightness. Learn to Phix programming.

## The Language to Learn

An interpreter is a computer application that reads the text of program and then acts on what was written. Surprise, you have to put a duplicate interpreter in your head in order to read and write computer programs. Luckily the Phix interpreter is small--it's simple.

Choose a language with off-by-one indexing, many data-types, OOP, classes and methods, overloading, trick syntax, formatting rules, only does interpreting ... then your langauge is not "easy to learn." In contrast, the Phix language is simple; it lets you both interpret and compile; it's crafted for programmers--it's sharp.

Phix programming has a nice bonus--it's speedy.

## Is it Simple?

Learn something and use it. No relearning to use different data-types. No relearning for changes in syntax. No relearning to accomodate surprises. You get to keep what you learn.

There are many examples of how Phix is more elegant than some popular conventional language.

In Phix operators always act the same way. In Phix `+` always adds. Therefore 2+2 is 4 , and 2+{1,2} is {3,4}, and 'A' + 32 is 'a' . Adding an atom value to every item in a sequence list is a natural extension of addition. The character 'A' has the number value 41 , thus 41+32 is 61 , and 61 is the number value of 'a' . Because it is predictable, Phix is simple.

In Phix you can always change the value of a list item. Given the sequence s = {1,2,3} , the statement s[1] = 88 , changes the sequence to {88,2,3} . If the sequence is s = "cat" , then statement s[1] = 'b' , changes the sequence to "bat" . Notice that actions work the same for numbers and text. Because it is regular, Phix is simple.

In Phix any value is either atom or sequence. A value is either one number (atom), or a value is many numbers (sequence)--just two choices. And for more universality, all values are object (atom or sequence). Because of atom|sequence, Phix is simple.

In Phix ideas are generic. For example the sorting function works the same with characters or numbers: sort({'c', 'a', 't'}) becomes {'a','c','t'}, and the same with mixed values sort( {"cat", {1,2}, 'A'} ) becomes { 'A', {1,2}, "cat"}. Because it is generic, Phix is simple.

As you learn more about Phix you will appreciate the programmer friendly design. With Phix "easy to learn" has real meaning.

## Value Action Flow

To make a computer do something you must understand: value, action, and flow. Value is "information, data, and numbers." Action is "changing values, creating values, doing something." Flow is "if, when, and in what order actions happen."

Save this text as the file hello.ex:

```-- Phix is simple, sharp, and fast
? "Hello Phix"
? 2 + sqrt(4)
```

An editor ready for Phix programming will let you press F5 to execute the program. Or, from a terminal you type:

```p hello
```

And you see:

```"Hello Phix"
4
```

The first value is a string of text "Hello Phix". The second value is the result from a number calculation 2+sqrt(4) . A line that begins with `--` has no action; it is a comment line. A line that begins with `?` has the action to output a value. The natural flow of a program is do the first statement (a comment does nothing), then the next (print some text), then the next (print a number) ... and stop when you run out of statements. You can always understand how a program works from value|action|flow.

continue to Value 2learnPhix

Not signed in.