Re: wikipedia draft
- Posted by _tom (admin) Jan 10, 2021
- 1748 views
Examples and Syntax
A syntax element uses English keywords (like while) and finishes with an end tag (like end while); no additional rules; no additional punctuation.
Learn one sample | Then just follow the pattern |
---|---|
-- a list of user defined error messages sequence e = { "attempt to divide by 0", "user error 1", "user error2" } -- the try catch block try integer i = 1/0 catch e ? e[E_USER] end try puts(1,"still running...\n") |
-- loop for i=1 to 10 do ? i end for -- branch if x>0 then ? "big" elsif x < 0 then ? "small" end if -- function function positive(integer n) if n>=0 then return True else return False end if end function |
-- output is attempt to divide by 0 still running... |
Explicitly tagged ends ("if ... then ... end if") maybe verbose but catch many errors and slip-ups, and avoids problems such as the dangling else.
The syntax is pragmatic, and it includes some redundancy.
- A comment line begins with double dashes - -, double slashes / /, or is enclosed by /* */ delimiters.
- Either = (for traditional programmers) or =: (for programming educators) may be used as an assignment operator.
The syntax is freeform'; you may write in a style that suits obvious needs.
Typical Style | Exploiting Freeform |
---|---|
if count < 6 then ? "pay donut tax" else ? "pay printed price" end if |
if count < 6 then ?"pay donut tax" else ?"pay printed price"end if |
x = 3 y = 4 h = 5 |
x=3 y=4 h=5
|
https://en.wikipedia.org/wiki/Dangling_else
One-Based-Indexing
From a discussion on the Julia website "What’s the big deal? 0 vs 1 based indexing" comes a simple explaination:
Steven_Sagaert Dec 2016 That’s exactly it. 1-based indexing is actual indexing like in mathematics, while 0-based “indexing” isn’t indexing at all but pointer arithmetic. This comes from C where an array is just syntactic sugar for a pointer.
One-based indexing allows extensive and intuitive operations on sequences.
https://discourse.julialang.org/t/whats-the-big-deal-0-vs-1-based-indexing/1102
Sequence Operations
Understanding how sequences work is the key to understanding Phix.
Phix uses one-based indexes.
The widespread use of 0-based indexes[8] stems from a paper[9] by Edsger W. Dijkstra and the benefits for pointer arithmetic[10], which Phix does not have.
There have been many other debates[11],[12] about the use of 0-based vs. 1-based indexing. In 0-based indexing the first,last,length are 0,n-1,n whereas in 1-based indexing they are 1,n,n. If the first element of an array is a[0], you cannot index the last as a[-0].
In a language that allows negative indexes from the end of the array (such as Python[13]), having all indexes in -2,-1,0,1,2 be meaningful will obviously catch fewer errors than when a[0] is always an error (as it is in Phix).
You don't need to explain 1-based indexing to anyone and you certainly don't need a diagram.
For these reasons, Phix uses 1-based indexing, similar to Julia[14]
[tom, need some clear examples here, thinking about this...]
Rosetta Code
Rosetta has over one thousand programming challenges, and states "...we do not (and cannot) have solutions to every task in every language."
Phix does not (although most can be emulated) directly support lambda expressions, closures, nested functions, currying, partial function application, function composition, function prototyping, monads, generators, anonymouse 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, metaprogramming, pointers (other than to raw allocated memory), topic variables, enforced singletons, safe mode, s-expressions, or formal proof construction.
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
Features
Paradigms: imperative, procedural, object-oriented
Standardized: No, the manual includes language specification
Type strength: strong
Type safety: safe
Expression of types: explicit, partially implicit
Type compatibility: duck
Type checking: dynamic, static
Parameter Passing Methods Available: copy on write, immutable reference, multiple returns
Garbage collection: Reference counting
Intended use: Application, Educational, General, High-level scripting, Text processing
Design goals: Simplicity, Readability, Ease of use
Execution modes
Interpreter Compiler