Built‑in Functions
EasyBite comes with a powerful suite of built‑in functions that you can use instantly—no installation, no setup, no fuss. These functions live in the global scope and handle everyday tasks like printing output, reading user input, and manipulating binary data. In the sections that follow, we’ll explore four of the most essential built‑ins in great detail, with clear, step‑by‑step explanations and plenty of examples that even a complete beginner can follow. Then we’ll show you how to bring in additional functions from EasyBite’s standard libraries, and finally point you to the full reference at /libraries/get-started
.
Table of Contents
- Built‑in Functions
Overview of Built‑in Functions
Built‑in functions are the first tools you reach for when writing EasyBite programs. Because they are part of the language core, you:
- Don’t need any
import
orinclude
statement (unless you want extra library functions). - Call them anywhere in your script simply by writing their name and parentheses.
- Combine them with your own functions to build complex behavior.
Every built‑in function has a defined purpose—some print to the screen, some read from the user, and others manipulate data structures. In the next sections, we’ll focus on four that form the foundation of most EasyBite programs: show
, showline
, input
, and bytearray
.
Output with show
The show
function is your go‑to for sending text or values to the console. It does not append a newline automatically, so you can control exactly how your output appears.
How It Works
- Syntax:
show(value)
- Parameter:
value
can be a literal string ("Hello"
), a number (42
), an expression (3 + 4
), a list ([1,2,3]
), or even the result of another function call.
- Behavior:
- Prints
value
immediately. - Cursor remains on the same line.
- Prints
Detailed Examples
// 1. Simple text
show("Welcome to EasyBite!")
// Console now shows: Welcome to EasyBite!
// 2. Printing numbers and expressions
show("2 + 2 = ")
show(2 + 2)
// Console: 2 + 2 = 4
// 3. Combining text and variables
set count to 5
show("You have ")
show(count)
show(" new messages.")
// Console: You have 5 new messages.
Because show
doesn’t move to a new line, you can build up a single line of output in pieces, which is useful for progress indicators or formatted tables.
Output with showline
While show
prints without a newline, showline
exists solely to print a blank line. It takes no arguments—you call it as showline()
—and it inserts one empty line in the output.
Why Use showline
- Separate sections of console output for readability.
- Add vertical spacing without printing any text.
- Emulate paragraph breaks in terminal applications.
Example Usage
show("Step 1 completed.")
showline() // Inserts one blank line
show("Step 2 starting...")
showline()
show("All done!")
Console Output:
Step 1 completed.
Step 2 starting...
All done!
Remember: because showline
takes no parameters, any attempt to pass an argument (for example, showline("Text")
) will result in a syntax error. Its only purpose is to make your console output cleaner and easier to read.
Reading Input with input
Interactivity begins with input
, which displays a prompt and pauses execution until the user types a response and presses Enter. Whatever the user types is returned as a string.
How It Works
- Syntax:
set variable to input(promptText)
- Parameter:
promptText
: a string that appears before the cursor, asking the user for information.
- Return Value:
- Always a string, even if the user types digits.
Detailed Examples
// 1. Asking for a name
set name to input("Enter your name: ")
show("Hello, " + name + "!")
from convert import toint
// 2. Numeric input conversion
set ageText to input("Enter your age: ")
set age to toint(ageText) // Convert string to number
show("In five years, you will be " + (age + 5))
// 3. Using input inline
show("Ready? Press Enter to continue.")
set _ to input("") // Prompt with empty string
show("Continuing...")
Because input
always returns text, whenever you need numeric or boolean values, remember to convert them explicitly with toNumber
, toBoolean
, or other conversion functions.
Working with Binary Data using bytearray
When you need to manipulate raw bytes—for example, reading a file or crafting a network packet—you use bytearray
. This built‑in creates a mutable array of integers in the range 0–255.
How It Works
- Create empty or zeroed:
set data to bytearray(length)
length
: the number of bytes, all initialized to0
.
- Create from list:
set header to bytearray([0xDE, 0xAD, 0xBE, 0xEF])
- Indexing:
- 1‑based indices:
data[1]
,data[2]
, … - Read or write:
set data[3] to 255
- 1‑based indices:
Detailed Examples
from convert import tostring
// 1. Initialize 4 bytes to zero
set buffer to bytearray(4)
// buffer = [0, 0, 0, 0]
// 2. Modify individual bytes
set buffer[1] to 0x48 // ASCII 'H'
set buffer[2] to 0x69 // ASCII 'i'
set buffer[3] to 0x21 // '!'
set buffer[4] to 0x0A // newline
// 3. Iterate and display hex values
set i to 1
repeat while(i <= buffer.length())
show("Byte " + i + ": ")
show(tostring(buffer[i]))
showline()
set i to i + 1
end repeat
// 4. Convert bytearray back to string (using library)
import string
set text to string.frombytes(buffer)
show("Message: " + text)
Bytearrays give you low‑level control over data, but you can combine them with library functions (such as string.frombytes
) to convert between text and binary.
Importing Functions from Built‑in Libraries
Beyond the core built‑ins, EasyBite provides standard libraries—collections of related functions you import when needed. Common libraries include math
, string
, io
, and more.
Import Syntax
- Import entire library
import math
Use with dot‑notation: math.sqrt(16)
- Import specific functions
from math import sqrt, pow
Call directly: sqrt(9)
- Alias a library
import string
set upper to string.toupper("hello")
Imports must appear before you call the functions you’ve imported.
Examples of Imported Functions
import math
import string
// Math: compute hypotenuse
set a to 3
set b to 4
set c to math.sqrt(a*a + b*b)
show("Hypotenuse: " + c)
showline()
// String: convert to uppercase
set greeting to "easybite"
set shout to string.toUpper(greeting)
show("Shout: " + shout)
By importing only what you need, you keep your code clear and avoid naming conflicts.
Conclusion
Built‑in functions like show
, showline()
, input
, and bytearray
form the foundation of EasyBite programming. They let you interact with the user, format output, and manipulate data at a low level—all without any setup. When you need more specialized behavior, import functions from EasyBite’s standard libraries using simple import
statements.
Full Reference
For a complete list of built‑in libraries and their functions, see the EasyBite documentation:
Full Built‑in Libraries Reference