|
A Fancy Calculator |
This Fancy Calculator showcases Sheerpower’s powerful
eval() function, which evaluates *all valid
Sheerpower expressions*. It handles arithmetic (e.g.,
2+3), variables, built-in functions (like
sin() or len()), logical
operators (e.g., and, or),
and string operations—everything Sheerpower supports as
an expression. Note: It does not execute arbitrary code
like loops or statements, ensuring security. The code
is below, with a detailed explanation. Try it out!
Program Explanation:
1. Introduction:
The program prints a welcome message and
instructions, noting that *any Sheerpower expression*
can be evaluated. Variables x,
y, and name$ are predefined
for use in expressions.
2. Input Loop:
A loop prompts the user with >> to
enter an expression, stored in expr$.
Typing 'Q' (case-insensitive) exits.
3. Expression Evaluation:
The eval() function evaluates any
valid Sheerpower expression from expr$.
Examples include:
2 + 3 →
5x * y →
50 (using x=10,
y=5)sin(45) → approx.
0.707name$ + " rocks" →
Sheerpower rocksx > 5 and y < 10 →
1 (true)4. Error Handling:
If an invalid expression is entered (e.g.,
5/0 or for i = 1 to 10),
the when exception in block catches it
and prints the error via extext$.
5. End of Program:
Upon quitting, it prints "done" and stops.
eval() processes
*all Sheerpower expressions*—math, strings, logic,
and functions like sqrt(x) or
len(name$). It won’t run full code
blocks (e.g., print "hi"), keeping it
secure and focused on expression evaluation.
|
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. |