Sage-Code Laboratory

Bee Syntax

Bee is multi-paradigm, statement oriented language with imperative keywords. We preffer verbs over substantives to make the keywords. Unlike other new languages, Bee is not a curly bracket language. Its syntax is inspired from Python, Pascal and Ruby.


This article is an overview of fundamenta concepts that are required to grasp before we can explain in details every aspect of Bee syntax. If this overview looks complicated do not warry, you will understend more in next articles.


We use examples and sometimes a simplified version of BNF notation to explain the syntax rules. If you do not know anything about BNF don't warry, here is a short introduction to this weard notation:


Comments are very important part of Bee code. We have multiple conventions for making good comments for any project. Bee comments are tailored by archtectural principle: "if there are no comments in the code the code is wrong."


In next example we are using various comments into a demo program.

| At the beginning of program you can have  several comments,     | 
| to explain how the program works. This notation is preferred.   |

#Section Title

##Rule subtitle 
/** This is a second comment notation used for:
    Notes before a rule begins, or ...
   /* Expression comments */
   /* Debug-code comments */   
rule main():
  ** This is a single line comment
  pass; // end of line comment
  ** In expression comments use /*...*/  
  print ("comment in expression \n", /*first line*/
         "is working \n",            /*second line*/
         "this is a test \n"         /*last line*/ 
        ); // end of expression
** This is the old style boxed comment, used for matrix printers **
** In Bee you can add comments/notes at the end of your code     **

Title comment

For single line title comments we use one "#" symbol. This can be used in combination with "!" to create "shabang" comment known in scripting languages on Linux to specify interpretor location. You can use two "##" for subtitles, usually before a rule.

Single line

For single line comments we use two stars like this: "**";

End of line

Before new line of code: (EOL) you can use comments starting with: "//"

Box comment

This notation is specific to Bee language. It is a multi-line comment starting with "+-" and end with "-+". The upper right corner is missing. I guess you will notice this defect later. However you can use old-style C comments.

Old style comments

This notation is supported in Bee for large section of blocks. It start with "/*" and end with "*/". Anything in between these two symbols are comments. Nested comments are supported. This kind of comments can be embedded in expressions. Therefore sometimes they are called "expression comments".



Expressions are created using identifiers, operators, rules and constant literals.


** demo some print statements
10 + 10 + 15
"this is a test"

** complex expressions 
(10 > 5) ∨ (2 < 3) 
-b + sqr(b² - 4·a·b)/(2·a)

** enumeration of expressions


Bee uses diverse identifiers names to data types. It uses ASCII characters and numbers or Unicode symbols. Most predefined data types have a longer name and a code. You can use both to represent a type. Lonf names are synonyms (alias) to the short name.


Z64      // primitive type: long integer
Integer  // same as Z64
Rational // same as Q(50.12)
File     // composite type: text file
List     // composite type: list of values


Bee has support for subscript to make identifiers. This is useful especialy in mathematical formulas for geometry and geography. You can use a limited number of characters offered by Unicode:

x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀
yₐ yₑ yₕ yᵢ yⱼ yₖ yₗ yₘ yₙ yₒ yₚ yᵣ yₛ yₜ yᵤ yᵥ yₓ


Bee has support for exponent using superscript. You can make any numeric exponent or variable exponent. Notice the variable is mapped to normal variables. The limitation is only lowercase variable names can be used as exponents. That makes constants impossible to use as exponents.

x⁺ x⁻ x¹ x² x³ x⁴ x⁵ x⁶ x⁷ x⁸ x⁹ x¹⁰
y° y′ y″ yᵃ yᵇ yᶜ yᵈ yᵉ yᶠ yᵍ yʰ yⁱ yʲ yᵏ 
yᶩ yᵐ yⁿ yᵒ yᵖ yʳ yˢ yᵗ yᵘ yᵛ yʷ yˣ yʸ yᶻ 


Bee has support for fractions. Bee is using regular slash "/" for all fractions. You can use superscript for left and subscript for right: These two are equivalent (1/2 = ¹/₂). Unfortunately we can not support fractional power due to lower readability.

¹/₂ ¹/₃ ¹/₄ ¹/₅ ¹/₆ ¹/₇ ¹/₈ ¹/₉  ¹/₁₀ ¹/₁₀₀ 
x⁻¹ = 1/x, x⁻² = 1/x², x⁻³ = 1/x³ ...

Power operations have priority but we have support only for (+, -) no other opperations are possible in exponent. In next expressions, (n-1) is done first before making the power operation.

//equivalent notations
xⁿ⁻¹ = powr(x,n-1)
xˣ⁺¹ = powr(x,n+1)

//supported  notations
x^(¹/₂) = sqrt(x,2)  //Symbol ^ is for power
x^(¹/₃) = sqrt(x,3)  //This will also work

Unicode Identifiers:

In mathematics is very popular notation for angles to use Greek leters. We support in Bee a limited number of Greek letters to make variable names. Also several Kirilik characters are permited.

Λ Γ Δ Ξ Π Σ Φ Ψ Ω α β ɣ δ ζ 
Б Г Д Ж И Л Ф Ц Ч Ш Щ Э Я 
η θ λ μ ν ξ ο π ρ σ ς τ υ φ ω

Lambda expressions

A lambda expressions is a named expression with parameters and specified result type:


** declaration of Lambda expression
make name := λ(param ∈ Type,...) ∈ ResultType => (expression);
** you can define a lambda signature first
type SigName: (Type,...) ∈ Type <: Lambda;
** then you can declare a λ variable
make name ∈ SigName; // Null Expression
** then you can modify assign expression to variable
alter name := λ(param ∈ Type,...) ∈ Type => (expression);


** define "exp" as Lambda expression
make exp: λ(x,y ∈ Z) ∈ Z => (xʸ);
** use introspection to chek what is "exp"?
print type(exp); // Lambda
** use the lambda expression
make z := 2·exp(2,3); 
print z; // 16


Lambda Expressions...



Lambda signature

Lambda expression signature is a type declaration;

** declare a rule signature
type CMP:(Z,Z) ∈ L <: Lambda;
** instantiate 3 Lambda expressions like "CMP"
make gt := (x, y ∈ Z) ∈ L => (x > y);
make lt := (x, y ∈ Z) ∈ L => (x < y);
make eq := (x, y ∈ Z) ∈ L => (x = y);
** define a dictionary of rules
type Dic: {(S(2) : CMP)} <: Hash;
** define a hash map of expressions
make dic := {('gt':gt),('lt':lt),('eq':eq)} ∈ Dic;
** call 3 rules in very unusual way
print dic['gt'](3,1); //1
print dic['lt'](3,1); //0
print dic['eq'](3,1); //0


Bee Keywords

Bee core has 58 reserved keywords so far:

alter alias and apply abort
other case  done default
if is do else exit
fail final given panic like
load next make match over
print pass rest rule return
fail retry none scrap type
read trial stop yield xor
write wait when or with
hide  begin  loop


Semantic keywords

Keyword Purpose
if conditional executopm of one statement
is query element or variable data type
or alternative for ladder decision
in alternative for belong operation
and alternative for cascade decision
xor alternative for logic operation
not alternative for logic operation

Definition statements

Next statements are used to declare new elements in a module.

Keyword Purpose
load Load module or module
alias Eliminate scope qualifier
hide Hiding public members from a loaded module
type Declare data super-type or sub-type in a module
make Create a new variable or multiple variables
stow Declare constant | Immutable variable
rule Create a new business rule or prototype
return End rule declaration and transfer control to caller

Execution statements

Next keywords are simple statements. These represents actions called imperative statements.

Keyword Purpose
apply Execute a rule and ignore the result if there is one
begin Commence execution of a coroutine
wait Suspend current thread execution for a number of seconds
read Flush the console buffer and accept user input from console
write Add something to console buffer but no new line
print Output expression result, variable or constant to console
alter Mutate variable value using an expression
scrap Remove one element from its collection

Control statements

Control statements are also known as selection statements.

Keyword Purpose
match Value multi-path search selector
when Create node values for match statement
none Create last node for a match statement
if Start a decision block or repetitive statement
else Alternative path for decision statement
given Start iteration for a domain or collection
trial Protect a block of code that may have exceptions
other Associated with trial to catch other errors
case Associated with trial to resolve specific errors
final Associated with trial to finalize the trial block
do Begin a statement region in a block statement
done Finalize with, when, case and trial control statements
cycle Cause a block to repeat or a condition to reevaluate

Transfer statements

These statements execute a jump or make an interruption of current thread.

Keyword Purpose
panic Create unrecoverable error code and stop current program
over Silent termination of program. No error is raised in this case.
exit Silently stop execution of current rule and return to the caller
yield Suspend one coroutine and give control to another routine
rest Suspend a routine and wait for all threads created by the routine to finish
stop Intrerupt execution for current cycle and continue after the cycle,
loop Continue current cycle from the beginning making a shortcut,
next Continue current iteration from the beginning making a shortcut,
abort Intrerupt early a trial block
fail Create error message if a condition is true else pass
pass Clear error message if a condition is true else fail
raise Stop trial case and re-issue last error
retry Clear error and repeat a trial block


In Bee operators are created using clasic ASCI symbols but also special Unicode symbols not available on your keyword. There is no option to use only ASCII symbols. This is why Bee language is considered ezoteric. It is a language difficult to use.


Symbol Description
+-...-+ Multi-line boxed comments
/*...*/ Old style C expression comments
#(....) String interpolation (placeholder) for operator "?"
(_,_,_) Expression | List literal
[_,_,_] Index | Array literals | Parameterize types
{_,_,_} Ordinal type | Set of values | Hash map


symbol description
'x' Fixed capacity Unicode UTF32 string literal
"y" Variable capacity Unicode string literal

Single Symbols

symbol description
! Negation symbol for relations | Excluded from domain
? Template modifier. Associated with string templates
* String replication | Varargs prefix | Spread operator | Many something
@ System variable | Global variable
$ System constant | Environment variables
& String concatenation | number concatenation
# Title | String interpolation
Define variable/constant/result/parameter type
_ Anonymous variable | Constant value = one space (_ = ' ')
+ Maximum upper limit for a domain | Unicode notation U+
- Minimum lower limit in a domain | Unicode notation U-
: Define type or rule or module
: Pair-up key-value in: objects, rule parameters, rule arguments, hash-map pairs
; End of statement | Statement separator
. Decimals for real numbers | Path string concatenation
. Membership dot notation | Prefix for public member/attribute
| Declarative collection builder: set := { x*2 | x ∈ (0..3)}
\ Exact divisor: since 15 = 3 · 5 then (3 \ 15 = True) and (5 \ 15 = True)
\ Escape character ( \n := New Line), ( \" = Double Quotes)

Numeric operators

Listed in the order of precedence top down.

symbol description
- Change sign, replace "y = -x" with "y = -1·x"
/ Rational number division
^ Power symbol used with fractions or expressions
· Multiplication
÷ Real division
× Array multiplication | Matrix multiplication
% Modulo operator 5 % 2 = 2
+ Numeric addition | List append | Mattrix addition
- Numeric subtraction | Collection difference
± Numeric tolerance (use with ≈)

Double Symbols

Double symbols is a group of two ASCII symbols considered as one.

symbol description
// End of line comments (not in expression)
## Single line subtitle comments (no indentation)
** Single line comments (allow indentation)
.. Define range/domain/slice (n..m) | [n..m]
.! Define range/domain with exluded limit (n.!m) | [n.!m]
!. Define range/domain with excluded limit (n!.m) | [n.!m]
!! Define range/domain with excluded limits: (n!!m) | [n.!m]
-. Minus infinite domain: instead of [-∞..0] write: [-..0]
.+ Plus infinite domain: instead of [0..+∞] write: [0..+]
=> Define: rule expression | rule result
<- Define and generate values in a loop from range or set
<: Define subset from set | Specify super-type for a new type
:> Data cast pipeline operator / Type conversion
<< Shift values of collection to right by removing first elements
>> Shift values of collection to left by removing first elements
:: Deep copy | Clone operator
++ Concatenate two lists or extend an array
-- Symmetric difference or shrink an array
-= Find and delete one element, from a collection
+= Apend an element in a set or a map but not in a list
+> Append element to beginning of a list
<+ Append element to end of a list


Each modifier is created with pattern "x=" where x is a single symbol:

symbol meaning
:= Modify | (value | reference)
+= Increment value
-= Decrement value
·= Multiplication modifier
÷= Real division modifier
^= Power modifier
%= Modulo modifier

Relation Operators

Relation operators are used to compare expressions.

symbol meaning
check if element belong to collection
= equal { compare values or attributes}
different { compare values or attributes}
identical | { compare types & values or attributes }
approximative equal numbers, used with ± like: (x ≈ 4 ± 0.25)
> value is greater than: (2 > 1)
< value is less than: (1 < 2)
greater than or equal to
less than or equal to


Operator: "!" can be used in combination with other operators:

 x != y; //equivalent to: ¬(x = y)
 x !≡ y; //equivalent to: ¬(x ≡ y)
 x !∈ y; //equivalent to: ¬(x ∈ y)
 x !≈ y; //equivalent to: ¬(x ≈ y)
 x !~ y; //equivalent to: ¬(x ~ y)

Collection operators

symbol result meaning
Set Intersection between two collections
Set Union between two collections
Logic Set is included in superset: "⊂"
Logic Set contain subset: "⊃"
Δ Set Set symmetric difference
+ String Concatenation between two strings
+ List Concatenation between two lists
+ Array Concatenation between two arrays
Element All: used in collection qualification
Logic One: used in collection qualification

Logic Operators

Bee is using enumeration symbols: True = 1 and False = 0

symbol meaning notes
¬ NOT unary operator
AND shortcut operator
OR shortcut operator
XOR exclusive OR
NOR p ↓ q = ¬ (p ∨ q)
NAND p ↑ q = ¬ (p ∧ q)

The table of truth

p q ¬ p p ⊕ q p ∧ q p ∨ q
1 1 0 0 1 1
1 0 0 1 0 1
0 1 1 1 0 1
0 0 1 0 0 0

Bitwise operators

Bitwise operators are processing numbers not Boolean values.

symbol meaning notes
« bit SHIFTL shift bits to left
» bit SHIFTR shift bits to right
~ bit NOT negate all bits
& bit AND execute AND between each bits
| bit OR execute OR between each bits
bit XOR execute XOR between each bits

Arity = 1

a ~ a a « 1 a » 2

Arity = 2

aba & ba | ba ⊕ b

String operators

*string pattern repetition (right operator must be numeric)
/concatenate url or path using / not depending on OS
.concatenate using \ or / depending on OS
+concatenate two strings as they are or a string with number.
?string format operator, replace "#" with number.

Read next: Structure