Bee Standard Library
Standard Library
Standard library contains:
Data rules
Introspection Rules
| rule | Purpose |
|---|---|
| type | type name |
| size | type size |
Bee Type System
Primitive types and composite types are all included automatically in the standard library. So you do not have to import any of it to use them in your algorithms. This will make basic runtime quite large but we hope it worth it to avoid all these imports.Composite Types
| rule | Purpose |
|---|---|
| length | type length |
| capacity | type capacity |
| min | type minim limit |
| max | type maxim limit |
List & strings Type
| rule | Purpose |
|---|---|
| split | Split a string into a list / array |
| join | Join a list into a string |
| find | Search one sub-string in a string |
| replace | Replace one sub-string in a string |
| trim | Remove blank spaces from string |
| right | Align string to right by adding spaces |
| left | Align string to left by adding spaces |
| center | Align string to center by adding spaces |
Numeric Type
| rule | Purpose |
|---|---|
| round | Convert one real into an integer |
| floor | Convert one real into an integer |
| parse | Convert one string into one number |
| random | Create random numbers |
Date Time
Modules for date and time will contain all required rules.
time
| rule | Purpose |
|---|---|
| now | get current time |
date
| rule | Purpose |
|---|---|
| now | get current date |
Error Type
Bee has pre-defined Error objects. Code allocation follows the system standard (spec/14 §5):
- 1 .. 199 : System Reserved Standard Error Codes (I/O, network, allocation).
- 200 .. 9999 : User / Application business-domain error codes.
- ≤ -1 : Unrecoverable hard hardware / memory-security panic.
Errors are surfaced through the global system variable $error:
-- global type
type SystemError: {code ∈ Z, message ∈ S} <: Object;
-- exception objects
$zero_division := {100,"division by zero"} ∈ Error;
$null_reference := {101,"null reference usage"} ∈ Error;
$value_overflow := {102,"value overflow"} ∈ Error;
$out_of_range := {103,"value out of range"} ∈ Error;
$type_mismatch := {104,"data type mismatch"} ∈ Error;
$user_error := {200,"user defined error"} ∈ Error;
...
-- Standard error
$standard_error := {1,"standard error"} ∈ Error;
$unexpected_error:= {2,"unexpected error"} ∈ Error;
Mathematic Rules
Math library will implement extra rules that are not available until you import "math" library. These are functions you rarely use and require extra memory space to be available in your program.
| rule | Purpose |
|---|---|
| sin | sinus |
| cos | cousin |
| tan | tangent |
| pow | power |
| sqr | square root |
| fac | factorial |
| mod | module rule y := |x| |
System Library
Interaction with operating system require load from library.
+-------------------------
\bee
|
|-- system
| |-- io.bee
|
|-- db
...
-------------------------+
File IO
To read and write files and save to disk, we import the $bee.sys.io namespace (spec/14 §4). This namespace defines the opaque file-handle type F and directory operations:
use $bee.sys.io as IO;
-- check existence, then create a folder
if IO.Folder.exist("data") = false then
apply IO.Folder.create("data");
done;
-- open a file handle in write mode ("r", "w", "a", "rw")
new file_handle := IO.File.open("data/output.txt", "w");
apply IO.File.write(file_handle, "Hello, Bee Compiler!");
apply IO.File.close(file_handle);
-- list a directory into a List of string paths
new file_list := IO.Folder.list("data/");
rules
Next is a fragment from system.io library that define rules open and close.
rule .open(name ∈ S, mode ∈ A) => (file ∈ File);
rule .close(file ∈ File);
rule .list(folder ∈ Folder) ∈ (S);
rule .exist(name ∈ S) ∈ B;
rule ,delete(name ∈ S);
rule ,rename(name, new_name ∈ S);
...
remember: public rules start with dot: "."
File IO
System IO rules
| rule | Purpose |
|---|---|
| open | Open a file |
| close | Close a file |
| exist | Check if file or folder exist on disk |
| list | Read a list of files and folders from directory |
| tree | Read tree of directory in memory |
| delete | Remove a file / directory |
| rename | Make a new directory |
Two data types must be available: File, Folder
File rules
- clean -- erase all data in the file
- flush -- save file buffer to disk
- change -- modify file attributes
Folder rules
- select -- select this folder as working folder
- purge -- remove all files from folder
- change -- modify folder attributes
Making files/folders
new file_name := IO.File.open("name", "w");
new folder_name := IO.Folder.create("name");
The system namespace hierarchy also exposes $bee.sys.math, $bee.sys.string, $bee.sys.time, and $bee.sys.env (spec/14 §1).
Go back to: Bee Index
Diagnostic error codes
Diagnostic codes raised by the Library module (spec/14 ยง7):
| Code | Violation | Mitigation / diagnostic action |
|---|---|---|
| E1401 | FileNotFound: Target file path missing during an open operation. | Create the file or correct the path. |
| E1402 | FileAccessDenied: Insufficient OS permissions to open or write a file handle. | Fix the permissions. |
| E1403 | UnclosedFileHandle: Scope exited with an unclosed F file handle. | Close the handle before scope exit. |
| E1404 | LibraryNotFound: Requested $bee.sys submodule not available in the runtime build. | Build with the required submodule. |
| E1405 | InvalidFileMode: File open mode is not r, w, a, or rw. | Use one of the four accepted modes. |