1. Phix wiki 3

When programming in Phix you learn to recognize similarities between data values and structures.

Complete Sequence Actions

Symmetrical indexing provides a complete set of operations for accessing|mutating items and slices in a sequence or string.

You can get an item or a slice from a sequence:

sequence s = { 1,2,3,4} 
          -- one item 
? s[1]    // 1 
 
          -- slice with one item 
? s[1..1] // {1} 
 
           -- slice with three items 
? s[1..3]  //  {1,2,3} 

Slicing is a left to right action:

sequence s = { 1,2,3,4} 
? s[1..3 ]              // {1,2,3} 
? s[1..-2]              // {1,2,3} 
 
//but 
? s[3..1]   --> error 
            -- slice length is negative [3..1] 

You can increase the length of a sequence by one item by appending, or the length n of a new sequence:

Appending increase the length of a sequence by one item. Concatenating increases the length of a sequence by the length n:

sequence s 
 
s = "jello" 
s = append(s, "jiggles" ) 
? s                      -- appending 
                         -- longer by one 
                         // { "jello", "jiggles" } 
 
s = "hello" 
s = s & ", world" 
? s                      -- concatenating 
                         -- longer by n = length(", world") 
                         // "hello, world" 

Prepending and concatenating to the head of a sequence works the same way.

A {} is an empty sequence, which is identical to "" an empty string. You can insert an empty sequence as an item, or use it to delete an item or slice:

sequence str 
 
str = "hello" 
str[1] = "" 
? str               -- mutating an item 
                    // { {}, 'e','l','l','o' } 
 
str = "hello" 
str[1..1] = "" 
? str                -- deleting an item 
                     // "ello" 

Slicing also works for concatenating slices:

string str 
 
str = "hello" 
str[1..0] = "hi, "    -- concatenate before first item 
? str                 //  "hi, hello" 
 
str = "hello"         -- concatenate within string 
str[4..3] = "***"     // "hel***lo" 
? str 
 
str = "hello" 
str[ $+1..$] = " be well"      -- concatenate after last item 
? str                          // "hello be well" 

Slicing works for inserting items:

sequence x = "hello" 
x[4..3] = { "###" }     -- creating a nested sequence 
? x                     //  {'h','e','l',"###",'l','o'} 
 
? flatten(x)            -- producing a string from nested 
                        //"hel###lo" 

Without symmetrical indexing values used for indexing and slicing differ, which is really hard to explain without specialized diagrams.

All possible changes to a string or sequence are handled simply with indexes and slices.

Debugging features

Source code safety is ensured by:

  • data type checking
  • enforcing subscript bounds
  • variables must be declared and explicitly assigned values
  • argument are passing by-value (but with the efficiency of copy-on-write)
  • no pointers

Additional features

The Phix developer is provided with:

  • human readable error messages
  • automatic memory management
  • garbage collection
  • interpretation and compilation of source code
  • gui libraries based on IUP
  • a standard library that includes features like: ipc, json, curl, zip, gmp, regular expressions, sockets, and unit testing
  • debugger and execution profiling
  • execution tracing

Rosetta Code

Phix does not directly support: lambda expressions, closures, nested functions, currying, partial function application, function composition, function prototyping, monads, generators, anonymous recursion, the Y combinator, aspect oriented programming, interfaces, delegates, first class environments, implicit type conversion (of the destructive kind), interactive programming, inverted syntax, list comprehensions, meta-programming, operator-function-builtin overloading, pointers (other than to raw allocated memory), topic variables, enforced singletons, safe mode, s-expressions, or formal proof construction.

The Rosetta website has over one thousand programming challenges, and states "...we do not (and cannot) have solutions to every task in every language."

Phix has over one thousand completed Rosetta examples. A compact language like Phix is not limited by its simple nature.

http://www.rosettacode.org/wiki/Rosetta_Code

Execution modes

Interpreter Compiler

new topic     » topic index » view message » categorize

2. Re: Phix wiki 3

[quote _tom]

Slicing is a left to right action:

sequence s = { 1,2,3,4} 
? s[1..3 ]              // {1,2,3} 
? s[1..-2]              // {1,2,4} 

Should that second slice be {1,2,3} also?

new topic     » goto parent     » topic index » view message » categorize

3. Re: Phix wiki 3

[quote euphoric]

_tom said...

Slicing is a left to right action:

sequence s = { 1,2,3,4} 
? s[1..3 ]              // {1,2,3} 
? s[1..-2]              // {1,2,4} 

Should that second slice be {1,2,3} also?

yup, - - and / / are line comments

_tom

new topic     » goto parent     » topic index » view message » categorize

4. Re: Phix wiki 3

[quote _tom]

euphoric said...
_tom said...

Slicing is a left to right action:

sequence s = { 1,2,3,4} 
? s[1..3 ]              // {1,2,3} 
? s[1..-2]              // {1,2,3} 

Should that second slice be {1,2,3} also?

yup, - - and / / are line comments

_tom

My comment had nothing to do with the comment marks. I was asking about the slicing result.

sequence s = { 1,2,3,4} 
? s[1..3 ]              // {1,2,3} 
? s[1..-2]              // {1,2,3} <-- fixed? 
new topic     » goto parent     » topic index » view message » categorize

5. Re: Phix wiki 3

My apology to euphoric and Irv.

I was 'multitasking' by watching football, which was not the best use of my time.

Euphoric, of course you are correct. I have made the edit.

thank you

be well
_tom

new topic     » goto parent     » topic index » view message » categorize

6. Re: Phix wiki 3

sequence x = "hello"  
x[4..3] = { "###" }     -- creating a nested sequence  
? x                     //  {104,101,108,"###",108,111} 
pp(x,{pp_IntCh,-1})     //  {'h','e','l', `###`, 'l','o'} 

And, at least grammatically,

argument are passing by-value 

should be

arguments are passed by value 

if not

arguments are passed by value (actually copy-on-write references: the efficiency of pass-by-reference but with the behaviour of pass-by-value) 

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu