Englar

A natural language programming language. Englar reads like English and runs like code. Every statement ends with a period. Indentation is purely for readability — the interpreter ignores it.

Introduction

Englar is designed around one idea: if you can say it, you can code it. Variables are declared with plain sentences, conditions read like questions, and loops read like instructions.

# A complete Englar program
let name be "World".
say "Hello, " joined with name joined with "!".

Syntax Rules

Englar has just four rules:

RuleDetail
Statements end with .Every line of executable code ends with a full stop.
Blocks end with end <keyword>.e.g. end if., end while., end define.
Comments start with #Anything after # on a line is ignored.
Indentation is optionalUse it for readability; the interpreter doesn't require it.

Variables

Declaring a Variable

Use let to create a new variable:

let score be 100.
let name be "Alice".
let active be true.
let result be nothing.

Reassigning a Variable

Once declared, drop the let:

score be 200.
name be "Bob".
Note: Variable names must start with a letter or underscore and contain only letters, digits, and underscores. They are case-sensitive.

Data Types

TypeExampleNotes
Number42, 3.14, -7All numbers are floating-point.
Text"hello"Enclosed in double quotes.
Booleantrue, falseLowercase only.
NothingnothingRepresents the absence of a value (like null).
List1, 2, 3See Lists.
Dictionary"a"=1, "b"=2See Dictionaries.

Output

Both print and say are identical — use whichever reads more naturally:

print "Hello!".
say "The answer is " joined with 42.
print score.

Collections are printed in Englar syntax — a list prints as 1, 2, 3 and a dictionary as "a"=1, "b"=2.

Input

Use get input to ask the user for a value. The result is always text — convert with as number if needed.

let name be get input "What is your name? ".
say "Hello, " joined with name.

let raw be get input "Enter a number: ".
let n be raw as number.

Arithmetic

Englar uses standard mathematical symbols and respects BEDMAS (Brackets, Exponents, Division/Multiplication, Addition/Subtraction).

OperatorMeaningExampleResult
+Addition3 + 47
-Subtraction10 - 37
*Multiplication3 * 412
/Division10 / 42.5
%Modulo (remainder)10 % 31
^Exponentiation2 ^ 8256
( )Brackets (highest precedence)(2 + 3) * 420
let area be 3.14159 * radius ^ 2.
let result be (10 + 5) * (10 - 5).    # 75
let rem be 17 % 5.                    # 2

Strings

Concatenation

let full be "Hello, " joined with name joined with "!".

Length

let n be length of "hello".    # 5
let n be length of myList.    # works for lists and dicts too

Character Access

let ch be "hello" at 0.    # "h"
let ch be word at i.

Conversions

let n be "42" as number.      # 42
let s be 100 as text.         # "100"

Conditions

Englar supports both English words and mathematical symbols for comparisons — use whichever feels right. Both forms can be mixed freely.

English formSymbol formMeaning
x is yx == yEqual
x is not yx != yNot equal
x is greater than yx > yGreater than
x is less than yx < yLess than
x is at least yx >= yGreater than or equal
x is at most yx <= yLess than or equal
x contains yList/string contains value

Logical Operators

if x > 0 and x < 100:
if name is "Alice" or name is "Bob":
if not active:

If / Otherwise

if score >= 90:
    print "Grade A".
otherwise if score >= 70:
    print "Grade B".
otherwise if score >= 50:
    print "Grade C".
otherwise:
    print "Grade F".
end if.
Note: You may have any number of otherwise if branches. The final otherwise: is optional.

While Loop

Repeats its body as long as the condition is true. Use stop. to exit early.

let i be 1.
while i <= 10:
    print i.
    i be i + 1.
end while.

# Early exit with stop.
while true:
    let x be get input "Enter 0 to quit: ".
    if x is "0":
        stop.
    end if.
end while.

Repeat Loop

Runs its body a fixed number of times. The count can be any expression.

repeat 5 times:
    print "hello".
end repeat.

let n be 10.
repeat n times:
    print "tick".
end repeat.

For Each Loop

Iterates over every item in a list.

let fruits be "apple","banana","cherry".
for each fruit in fruits:
    print fruit.
end for.

# Summing a list
let total be 0.
for each n in nums:
    total be total + n.
end for.

Lists

Lists are ordered, zero-indexed collections of any values.

Creating a List

let nums be 1,2,3,4,5.
let names be "Alice","Bob","Carol".
let mixed be 1,"two",true.

Accessing Items

let first be names at 0.    # "Alice"
let last be names at 2.     # "Carol"

Modifying a List

add "Dave" to names.          # append to end
remove last from names.       # remove last item
remove first from names.      # remove first item

Length

let n be length of names.
Note: List indices start at 0. Accessing an out-of-bounds index returns nothing.

Dictionaries

Dictionaries store key-value pairs. Keys are text strings; values can be any type.

Creating a Dictionary

let person be "name"="Alice","age"=30,"city"="London".
print person.    # "name"=Alice, "age"=30, "city"=London

Reading a Value

let n be person at "name".    # "Alice"
print person at "age".        # 30

Setting / Updating a Value

person at "age" be 31.
person at "email" be "alice@example.com".    # adds a new key

Missing Keys

Reading a key that doesn't exist returns nothing rather than an error, which makes safe lookups easy:

let val be person at "phone".
if val is nothing:
    print "No phone on record.".
end if.

Dictionary as a Lookup Table

let grades be "A"=90,"B"=80,"C"=70,"D"=60.
let minimum be grades at "B".    # 80

Functions

Defining a Function

define greet with name:
    say "Hello, " joined with name joined with "!".
end define.

# No parameters
define separator:
    print "---".
end define.

Returning a Value

define add with a and b:
    give back a + b.
end define.

define max with a and b:
    if a >= b:
        give back a.
    end if.
    give back b.
end define.

Calling a Function

# Discard the return value
call greet with "Alice".
call separator.

# Use the return value
let result be call add with 3 and 4.
print "Sum: " joined with result.

# Call inside an expression
print call add with 10 and call max with 3 and 5.
Multiple parameters: Separate them with and — both in the definition and the call. e.g. define volume with w and h and d: / call volume with 3 and 4 and 5.

Recursion

Functions can call themselves. Always include a base case to stop the recursion.

define factorial with n:
    if n <= 1:
        give back 1.
    end if.
    give back n * call factorial with n - 1.
end define.

print call factorial with 6.    # 720

Math Built-ins

ExpressionMeaningExampleResult
sqrt of xSquare rootsqrt of 14412
root n of xNth rootroot 3 of 273
x ^ yPower2 ^ 101024
x % yModulo17 % 52
let s be sqrt of 256.              # 16
let c be root 3 of (8 * 8 * 8).     # 8
let hyp be sqrt of (3 ^ 2 + 4 ^ 2). # 5

Random Numbers

Generates a random whole number in an inclusive range. Both bounds can be any expression or variable.

let roll be random number from 1 to 6.
let coin be random number from 0 to 1.
let noise be random number from -100 to 100.
let pick be random number from 0 to length of myList - 1.

Type Conversions

ExpressionEffectExample
x as numberParse text to a number"3.14" as number3.14
x as textConvert any value to text42 as text"42"

Keyword List

These words have special meaning in Englar and cannot be used as variable names:

let  be  print  say  if  otherwise  end  while  repeat  times
for  each  in  define  with  give  back  stop  add  remove
last  first  from  call  and  or  not  true  false  nothing
as  number  text  length  of  sqrt  root  random  get  input
joined  to  between  at  is  contains

Cheat Sheet

Variables

CodeMeaning
let x be 10.Declare variable x
x be 20.Reassign existing variable
x at "k" be val.Set dict/list entry

Control Flow

CodeMeaning
if cond: ... end if.Conditional
otherwise if cond: ...Else-if branch
otherwise: ...Else branch
while cond: ... end while.While loop
repeat n times: ... end repeat.Count loop
for each x in list: ... end for.For-each loop
stop.Break out of current loop

Functions

CodeMeaning
define f with a and b: ... end define.Define function
give back value.Return a value
call f with x and y.Call (discard result)
let r be call f with x.Call and capture result

Lists & Dicts

CodeMeaning
let l be 1,2,3.Create list
let d be "a"=1,"b"=2.Create dictionary
l at 0Access by index
d at "key"Access by key
add x to l.Append to list
remove last from l.Pop last item
remove first from l.Pop first item
length of lLength of list/dict/string