Pharos

Reference

The whole language on one page, for when you know what you want and only need to check how it is spelled. If you are meeting Pharos for the first time, the guide is the better place to start.

How a program is laid out

RuleDetail
One statement per lineThere are no semicolons. A line break ends a statement.
Blank lines are freeUse them wherever they help.
Indentation is for youPharos does not measure it. Being consistent still pays.
Notes start with --Everything to the end of that line is ignored.
Keywords ignore caseIf and if are the same word. Variable names do not ignore case, so score and Score are two different variables.
Files end in .pharosBy convention, not by rule.

Kinds of value

KeywordHoldsWritten as
numA number, whole or fractional, positive or negative.0, 42, -7, 3.5
stringA piece of text."Ada", 'Ada'
boolA yes-or-no value.true, false

Text can use single or double quotes, as long as the pair matches. Inside text, \n is a line break, \t is a tab, and \" is a quote that does not end the text.

Variables

FormMeaning
num x = 5Introduces x and fixes it as a number forever.
x = 6Changes a variable that already exists.

A starting value is required; there is no way to declare a variable and leave it empty. Declaring the same name twice in the same place is an error, as is assigning a value of the wrong kind, or assigning to a name that was never declared.

Variables declared inside an if, a loop or a codeblock belong to that block and are gone when it ends. Assigning to a name from an enclosing block changes that outer variable rather than making a new one.

Printing

FormMeaning
print xWrites x followed by a line break.
out xThe same thing.
output xThe same thing again.

Text is printed without its quotes, and whole numbers without a decimal point.

Arithmetic

OperatorDoesNotes
+Adds numbers, or joins text.If either side is text, the result is text.
-Subtracts.Numbers only.
*Multiplies.Numbers only.
/Divides.Numbers only. Dividing by zero is an error.
-xMakes a number negative.Numbers only.

Division gives an exact answer rather than rounding, so 7 / 2 is 3.5. There is no remainder operator yet.

Questions

QuestionTrue whenWorks on
a is greater than ba is largernumbers
a is less than ba is smallernumbers
a is equal to bboth are the sameany two values of the same kind
a is not equal to bthey differany two values of the same kind

Comparing two different kinds of value is an error rather than simply false, because it is nearly always a mistake.

Combining questions

OperatorTrue whenNotes
a and bboth are trueIf a is false, b is never looked at.
a or bat least one is trueIf a is true, b is never looked at.
not aa is false

These work only on true and false. A number is not treated as a stand-in for either.

Choosing

if question then
  ...
otherwise if question then
  ...
otherwise
  ...
end if
PartRequiredNotes
if ... thenyesThe question must be true or false.
otherwise if ... thennoAs many as you like. Tried from the top down.
otherwisenoAt most one, and it goes last.
end ifyes

Repeating

loop until question
  ...
end loop

The question is checked before each pass, so a loop whose question starts out true never runs at all. A loop that runs a million times without its question becoming true is stopped and reported, on the assumption that something inside it forgot to change.

Codeblocks

codeblock name with first, second
  ...
  give back value
end codeblock
FormMeaning
codeblock nameStarts a codeblock that takes nothing.
codeblock name with a, bStarts one that expects two values.
give back xStops the codeblock and answers with x.
end codeblockEnds the definition.
nameRuns a codeblock that takes nothing.
name with 1, 2Runs one, handing over two values.

The values a codeblock expects have no declared kind, so they accept whatever is handed over. Handing over the wrong number of values is an error. A codeblock can see the variables around it and may change them, and it may call itself. Calling itself ten thousand deep without finishing is stopped and reported.

Everything after with is read as the values being handed over, to the end of the line. When a call sits inside a larger expression, put brackets around it: print "total: " + (add with 1, 2).

What binds tightest

Loosest at the top, tightest at the bottom:

LevelOperators
1or
2and
3is equal to, is not equal to
4is greater than, is less than
5+, -
6*, /
7not, negative -
8with

Brackets override all of it.

Running Pharos

CommandDoes
pharos run file.pharosRuns a program.
pharos file.pharosThe same, with less typing.
pharos replOpens a prompt that keeps what you have typed.
pharos versionPrints the version.
pharos helpPrints the commands.

A program that fails leaves a non-zero exit status, so Pharos behaves properly inside scripts and other tools.

Words Pharos keeps for itself

These cannot be used as variable names: num, string, bool, true, false, print, out, output, if, then, otherwise, loop, until, codeblock, with, and, or, not.

end, is, give and back are only special as part of a longer phrase (end if, is equal to, give back), so on their own they are ordinary names.

← Guide Examples →