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.
#!/bin/bee
+------------------------------------------------------------------
| 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
return;
*******************************************************************
** This is the old style boxed comment, used for matrix printers **
** In Bee you can add comments/notes at the end of your code **
*******************************************************************
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.
For single line comments we use two stars like this: "**";
Before new line of code: (EOL) you can use comments starting with: "//"
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.
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 + 10 + 15
"this is a test"
** complex expressions
(10 > 5) ∨ (2 < 3)
-b + sqr(b² - 4·a·b)/(2·a)
** enumeration of expressions
(1,2,3)
(1,',',2,',',3)
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
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.
Λ Γ Δ Ξ Π Σ Φ Ψ Ω α β ɣ δ ζ Б Г Д Ж И Л Ф Ц Ч Ш Щ Э Я η θ λ μ ν ξ ο π ρ σ ς τ υ φ ω
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...
restrictions:
result:
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 core has 47 reserved keywords so far:
alter | alias | and | apply | begin |
cover | case | defer | done | default |
if | is | do | else | exit |
fail | final | given | abort | like |
load | next | make | orif | over |
pass | patch | rule | return | |
fail | retry | stop | scrap | type |
read | trial | skip | yield | xor |
write | wait | when | while | with |
resolve | solve |
Keyword | Purpose |
---|---|
if | conditional executopm of one statement |
is | query element or variable data type |
or | alternative for logic operation |
in | alternative for belong operation |
and | alternative for logic operation |
xor | alternative for logic operation |
not | alternative for logic operation |
Next statements are used to declare new elements in a module.
Keyword | Purpose |
---|---|
load | Load module or module |
alias | Eliminate scope qualifier |
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 |
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 |
solve | Commence execution of an aspect module |
defer | Postpone execution of an aspect module |
wait | Suspend current thread execution for a number of seconds |
resolve | Suspend current thread and wait for sub-processes to finish |
read | Flush the console buffer and accept user input from console |
write | Add something to console buffer but no new line |
Output expression result, variable or constant to console | |
alter | Mutate variable value using an expression |
scrap | Remove one element from its collection |
Control statements are also known as selection statements.
Keyword | Purpose |
---|---|
when | Execute statement block only if condition true |
else | Alternative path for when statement |
orif | Alternative path for decision ladder |
case | Conditional search multi-path selector |
while | Start conditional repetitive block |
with | Start iteration for a domain or collection |
trial | Protect a block of code that may have exceptions |
cover | Associated with trial to catch other errors |
patch | Associated with trial to patch any other 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 |
These statements execute a jump or make an interruption of current thread.
Keyword | Purpose |
---|---|
abort | Create unrecoverable error code and stop current program |
over | Force silent termination of a rule, module, program or driver |
exit | Silently stop execution of current rule and return to the caller |
yield | Suspend one coroutine and give control to another routine |
stop | Stop execution for current cycle and continue after the cycle, |
loop | Continue current cycle from the beginning making a shortcut, |
fail | Create error message if a condition is true else pass |
pass | Clear error message if a condition is true else fail |
retry | Repeat a trial block a second time |
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 |
[_,_,_] | Range | 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 |
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) |
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 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 (n..m) | [n..m] | Define array slice [n..m] |
.! | Define range/domain (n.!m) | [n.!m] (m is excluded) |
!. | Define range/domain (n!.m) | [n!.m] (n is excluded) |
!! | Define range/domain (n!!m) | [n!!m] (n,m are excluded) |
-. | Minus infinite range: instead of (-∞..0) write: (-..0) |
.+ | Plus infinite range: 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 | += | Appemd am 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 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 |
negation:
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)
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 |
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) |
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 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 |
a | ~ a | a « 1 | a » 2 |
---|---|---|---|
0000 | 1111 | 0000 | 0000 |
1111 | 0000 | 1110 | 0011 |
0111 | 1000 | 1110 | 0001 |
0110 | 1001 | 1100 | 0001 |
a | b | a & b | a | b | a ⊕ b |
---|---|---|---|---|
00 | 00 | 00 | 00 | 00 |
01 | 00 | 00 | 01 | 01 |
11 | 01 | 01 | 11 | 10 |
10 | 11 | 10 | 11 | 01 |
Symbol | Description |
---|---|
* | 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