|
Variables, Data Types, Declaring Variables, Comments, and Database Access |
Welcome to the fundamentals of Sheerpower! In this tutorial, you'll learn how to store information in variables, understand the different types of data you can use, and how to document your code with comments. Let's get started!
Variables are containers for storing data. In Sheerpower, a
variable name must begin with a letter and can contain letters,
numbers, and underscores. Variable names are case-insensitive and
typically use underscores to improve readability, like
tax_rate or full_name$.
Sheerpower reserves two throw-away identifiers:
_ for numbers and _$ for strings.
They are write-only targets—assign to them when you want an
expression to run but ignore its return value. This makes your
intent clear at a glance. For example, the join() function
quickly joins strings together and returns the final length. If we
don't need the length, we can do this:
Every variable holds a specific type of data. Sheerpower's core data types are:
For text.
"Hello!"
For numbers.
123.45
For true/false.
true
Rarely used. Use REAL instead. Sheerpower's REAL type handles whole numbers perfectly, making a separate INTEGER type unnecessary for most arithmetic.
42
Inherits the data type of the last value assigned.
dynamic data types?
Variables can be created either implicitly (by using type suffixes)
or explicitly (with the declare statement).
$ for a STRING (e.g., name$)? for a BOOLEAN (e.g., is_done?) — makes code easier to scan% for an INTEGERdeclare): Improves clarity,
organizes declarations, and reduces errors.
OPTION REQUIRE DECLARE to enforce explicit
declarations. The compiler will raise an error if a variable
is used without being declared first.
Sheerpower’s REAL type is designed for exact decimal
arithmetic. Unlike IEEE floating-point types used in most languages,
REAL values deliver 16 digits of true decimal precision,
avoiding the rounding errors that plague floating-point math.
This makes REAL ideal for financial, accounting,
and scientific applications where accuracy is critical.
REAL is stored as two 64-bit integers:
one for the integer part (IP) and one for the fractional
part (FP), scaled by 1016.
For example, 13.599 is represented as:
This design eliminates floating-point approximation and enables
efficient hardware-level comparisons and arithmetic.
Expressions like (0.1 + 0.2) - 0.3 evaluate to
0 in Sheerpower.
By contrast, the same expression in IEEE math yields:
0.00000000000000005551115123125783
(0.1 + 0.2) - 0.3
Sheerpower is strongly typed. A STRING value—even one
like "123.45"—cannot be assigned to a REAL
variable. This results in a compile-time error.
Sheerpower lets you define your own constants and custom data types. These features make code more readable, expressive, and secure.
This makes code more self-explanatory—using money
signals financial data, not just a number.
If the program crashes, password appears as
<nodump> in debug output—protecting secrets
from accidental exposure.
nodump modifier ensures those
values are hidden, showing <nodump> instead of
the actual contents.nodump for secrets or private
data to keep applications safe without extra coding effort.
$ – Literal dollar sign%.2m – Two decimal places in monetary format
Sheerpower provides a secure way to access table fields using
table_name(field_name). This separates code from data
and protects against SQL injection.
This is an advanced feature—beginners can skip ahead and revisit it later. To learn more, see the Integrated Database Access tutorial.
Comments are ignored by the compiler and help others understand your code.
Use // (preferred) or ! to begin a comment.
Sheerpower enforces variable types. You cannot assign a STRING directly
to a REAL or vice versa — use conversion functions.
For a complete walkthrough, see the val() function tutorial .
Conversions like val() and str$() are
commonly used when reading user input, importing raw data, or
constructing strings for display.
OPTION REQUIRE DECLAREnodump)declare format! and //)val() and str$()declare.REAL is the default type with exact 16-digit precision.OPTION REQUIRE DECLARE) enforces explicit declarations.val() to convert strings to REAL values.str$() to convert numbers/booleans to strings.const) cannot be changed after declaration.nodump).declare format sets default printed output style.table(field) syntax._ and _$ names to discard results; they’re write-only.
This makes intent clear: run it and ignore the return value.! or // for meaningful comments.|
Hide Description
|
|
|
Enter or modify the code below, and then click on RUN |
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |