Popup YouTube Video
Sheerpower Logo

Introduction to the REPL and Interrupting a Running Program


Everything in this section assumes that you have already installed Sheerpower. The install typically takes less than three minutes. Installing Sheerpower Step-by-Step

To use these post-install tutorials, you will work with the SPDEV IDE that was installed on your desktop, or Visual Studio Code with the Sheerpower extensions installed. If you need help getting started, see Writing and Running Sheerpower Programs.

Note: The online Sheerpower tutorials restrict interactive use of certain features, since misuse could cause the server to become unresponsive for other users. This section is intended for developers who have installed Sheerpower locally, where they can safely explore and use all features without such restrictions.

The Sheerpower REPL — Read—Eval—Print Loop

You can open the Sheerpower console in several ways: by starting SPDEV, using Visual Studio Code, or typing sp4gl at the Windows command prompt. This launches the Sheerpower console, which functions like a REPL (Read—Eval—Print Loop) found in many other programming languages. A REPL is an interactive programming environment where you enter code, have it evaluated immediately, and see the results printed right away. In Sheerpower, you can also enter multiple statements on a single line by separating them with a backslash (\).


C:> sp4gl Sheerpower V011.0nn.nn -- Type KEYS or HELP for assistance C:\Sheerpower\sp4gl_cmds.txt -- Starred: 1 History: 0 Abbreviations: 2 >>> a=355 >>> b=113 >>> print a/b 3.1415929203539823 >>> >>> a=355\b=113\print a/b 3.1415929203539823 >>>

Each section below opens with the idea; click a Show me line for the keystrokes and examples, or Expand all.

Printing and Inspecting a Value

There are three ways to see a value at the prompt. print expr is the full statement; as a shorthand, a line that begins with = prints the expression, and so does simply typing the expression on its own line:

>>> a = 355 >>> =a / 113 3.1415929203539823 >>> a / 113 3.1415929203539823 >>>

To inspect a variable — its type and its value — begin the line with ?. Sheerpower prints the variable's typeof$ description, then its value:

>>> a = 355 >>> ?a Name:A, Dtype:Real, *Narrow* 355 >>> >>> dim scores(*) >>> fill scores with 90, 85, 77 >>> ?scores Name:SCORES, Dtype:Real, *Array*, Dims:1, Bounds:1:3, Size:3, *Expandable* 90, 85, 77 >>>

? works on any variable: a scalar, an array (you see its bounds and size, then the elements), or a cluster (you see *Cluster* and its row count).

Tab Completion

Press TAB and Sheerpower completes what you are typing, aware of the grammar at that point in the statement. When one completion fits it is filled in for you; when several fit, a Choices menu opens; a misspelling is corrected to the closest match.

Show me: what TAB completes, and an example

It completes:

  • statement keywords and the options a statement takes (after print you are offered at, using, the screen colors, then the functions);
  • built-in function names;
  • your own variables, arrays, and cluster names;
  • a cluster's members after -> — type cities-> then TAB to list city$, country$, …
>>> cluster cities: city$, country$, population >>> print cit ← press TAB → print cities >>> print cities-> ← press TAB → a menu: city$ country$ population

Keys — For a list of special keystrokes available to you

Type keys at the prompt and the console prints a one-screen reference of every special keystroke it understands, grouped by purpose — Editing the line, Completing, Remembering, Running, and the Console words themselves. Everything covered on this page is listed there — TAB completion, your abbreviations, Ctrl/R history search, Ctrl/S starring, ALT/B to halt a running program — so it is the quickest reminder when you forget a key, without leaving what you are doing.

Show me: the full keys reference
>>> keys The console's keys (the prompt is >>> ; runs the command) Editing the line - move along the line - ctrl/u clear to the start of the line - ctrl/a toggle insert / overwrite Completing - complete the word: a keyword, option, function, variable, cluster, or a cluster's member after -> - name. your abbreviation: its text appears on the next line Remembering - walk back and forth through earlier commands - ctrl/r search the history by what you typed, starred first Running - run the line - ctrl/c interrupt a running program - alt/b halt a running program and enter the console there Console words - help open the getting-started page - edit edit this source code - keys this list - ?name inspect a variable, array or cluster

Help — For access to this tutorial

Type help at the prompt to open the getting-started page — this tutorial — in your browser, so the language reference and the worked examples are always one word away. Both keys and help are named in the console's opening banner (Type KEYS or HELP for assistance), so you never have to remember where to find them.

>>> help

Shorthand — Type an Abbreviation, Press Enter

Type an abbreviation with its dot and press Enter: its expansion appears on the next line, already typed, with the cursor at the end. Press Enter again to run it — the same keystroke twice — or edit it first, or press Ctrl/U to erase it and walk away.

Show me: expanding abbreviations, and the built-in shorthand table
>>> t. ← Enter >>> run 'sptests:sptest' ← the expansion, ready: Enter runs it

TAB expands an abbreviation too — in place, so it works in the middle of a line as well, and pressing TAB after each one lets you expand several abbreviations into a single line as you type it.

>>> ot. ← TAB → >>> open table >>> cc. ← TAB → >>> collect cluster >>> if done? then xr. ← TAB mid-line → if done? then exit routine

The built-in shorthand:

ot. open tablein. includer. routine
of. open fileex. excludeer. end routine
et. extract tablesb. sort bypr. private routine
ee. end extractsd. sort descending bywe. when exception in
st. set tablep. printu. use
cc. collect clusterpc. print #ew. end when
ec. end collectpa. print atsc. select case
ac. add clusterpe. print _extractedce. case else
ea. end addli. line inputes. end select
fe. for eachlm. line input menuei. end if   ed. end do
ne. nextls. line input screenxd. xf. xr. exit do / for / routine
e. editl. list

You do not have to remember them: a lone . and Enter (or TAB) pops up an Abbreviations menu of every one (your own first, then these); pick one and it lands on the line. o. and TAB narrows the menu to the ones starting with o, and when only one fits it simply expands. keys prints every keystroke and console word on this page, in colour.

Your Own Abbreviations

Define an abbreviation right at the prompt — a name ending in a dot, an equals sign, and what it stands for. Nothing is echoed; it is in effect at once and kept for good.

Show me: defining, removing, and starring your own
>>> pt. = print typeof$(x) >>> t. = run 'sptests:sptest' >>> t. ← Enter: the expansion lands, ready >>> run 'sptests:sptest' >>> pt. = ← removes it pt. removed

A starred abbreviation is listed first in the .-TAB menu, marked with a *: define it as *t. = run 'sptests:sptest', or star an existing one with *t. (the same again un-stars it), or press Ctrl/S with just t. on the line. Your own abbreviations take precedence over the built-in ones, so ot. can be made to mean whatever you like.

Fill-in Abbreviations — Holes

An abbreviation can leave holes to fill in. Write a hole as {name}. When you expand the abbreviation, the first hole is selected — shown in reverse video — and whatever you type replaces it. Tab moves to the next hole, Shift/Tab back, and Enter moves to the next hole until none are left, then runs the line. Ctrl/U erases the whole thing if you change your mind.

Show me: holes, same-name fill, defaults, and block skeletons
>>> x. = for {var} = 1 to 10\print {var}\next {var} >>> x. ← Enter (or TAB): expands, cursor waiting in the first hole >>> for idx = 1 to 10\print idx\next idx ← type idx once

Two touches make this fast. A hole's name matters: every hole with the same name fills together, live, as you type — type idx once and all three {var} become idx. And a hole may carry a default, written like a named option, {name: value}: tab past it to accept the default, or type to replace it.

>>> of. = open file {ch}: name '@{file}', access {access: input} >>> of. ← fill ch and file ; tab past access to accept input

The built-in block abbreviations already use holes, so et., cc., fe., sc., we., do. and fo. drop in a ready-to-fill skeleton. Because the console runs one line at a time, a multi-line skeleton lands as a single line joined by \ (Sheerpower's statement separator) — it runs exactly as the block would.

Holes are only for abbreviations. Braces you type yourself — in a definition, or JSON inside a string — are ordinary text; the fill-in behaviour happens only when an abbreviation expands to holes.

Editing and Organizing Your Abbreviations

To change an abbreviation, just define it again with the same name — the new expansion replaces the old one. There is no separate edit step, and no need to remove it first.

Show me: redefining, and bulk-editing in sp4gl_cmds.txt
>>> g. = print 'hello' >>> g. = print 'hello, ' + name$ ← same name: this is now what g. means >>> g. ← removes it g. removed

Defining one at a time at the prompt is convenient for a quick abbreviation. Once you have a handful you care about — and especially the complex, hole-filled ones you do not want to retype — edit them in bulk in the file where they live: the [abbreviations] section of sheerpower:sp4gl_cmds.txt (see The Console's Memory, below). Each abbreviation is one line, name. what it expands to, exactly as you would type the definition; a hole is just {name} in that line, so a whole block skeleton is one editable line. A // line is a comment — use them to group and label your abbreviations.

[abbreviations] // --- my project shortcuts --- t. run 'sptests:sptest' * rp. run 'reports:monthly' // --- editing skeletons (holes) --- nr. add table {tbl}\{tbl}(id) = _gid$\{tbl}({field}) = {value}\end add

The console rewrites that file for you whenever you star something or run a console command, so your hand edits and your prompt-defined ones live together, survive between sessions, and travel with the file if you copy it to another machine.

Recalling Earlier Commands

The Up and Down arrow keys walk back and forth through the commands you have already typed, so you can rerun or edit one without retyping it. The console keeps the last 500, and carries them all over to your next session, so tomorrow starts with today's commands already there.

Searching the History — Ctrl/R

When the command you want is further back, type the first few characters and press Ctrl/R. A pop-up lists every earlier command that starts with what you typed (case does not matter), newest first — the starred ones first of all, above a rule. With nothing typed it lists them all. Pick one and it lands on the line, ready to run or edit; ESC leaves the line as it was.

Show me: the Ctrl/R history pop-up
>>> pr ← Ctrl/R → History * print cities->city$ ------ print 5+10 print 'hi'

Starring a Command — Ctrl/S

A command you use all the time can be starred: with it on the line, press Ctrl/S and the console answers Starred. From then on it heads the Ctrl/R list, in this session and every later one. To un-star it, recall it onto the line and press Ctrl/S again: Un-starred — it drops back into the plain history where its age puts it. Up to twenty commands can be starred.

The Console's Memory — sp4gl_cmds.txt

Everything above lives in one plain-text file next to sp4gl.exe: sheerpower:sp4gl_cmds.txt. The console names it, with its counts, on the line after the banner:

Show me: the file's two sections and how it is kept
Sheerpower V011.029.07 -- Type HELP for assistance c:\sheerpower\sp4gl_cmds.txt -- Starred: 2 History: 100 Abbreviations: 3 >>>

The file has two sections, and you may edit it by hand:

// sp4gl_cmds.txt -- the console's memory.  [history] is the last 500 commands, oldest
// first; a line starting "* " is a starred command (Ctrl/S) and is kept for good.
// [abbreviations] is yours to edit.
[abbreviations]
// name. what it expands to   (the dot is optional; TAB adds a space after the expansion;
//  a * in front = starred: listed first)
* t. run 'sptests:sptest'
pt. print typeof$(x)

[history]
* print cities->city$
print 5+10
print 'hi'
  • [abbreviations] (an older file's [shortcuts] header is still read, and the next save renames it): one per line as name. what it expands to — the dot is assumed if you leave it out, a leading * stars it, a line starting // is a comment. The expansion is taken as written; TAB puts one space after it when it ends in a letter or digit.
  • [history]: the commands, oldest first, newest at the bottom; a * prefix marks a starred one.

The console writes the file whenever you star something, whenever you type a console command such as run, save, edit, build, new, old, exit or stop, and when it exits — so it is never more than one real action behind, even if a session ends badly. Only the section being written is touched; your comments and ordering in the other one are kept as they are.

Scripted sessions: under sp4gl /headless < transcript.txt every menu — the Ctrl/R list, the Abbreviations list, a program's line input menu — comes out as numbered text and reads its pick from the next line of the transcript, and a raw Ctrl/R or Ctrl/S byte in a transcript line means that keystroke at that point. So everything on this page can be exercised, and pinned in a regression test, without a window.

Writing a Program in the REPL

You do not have to leave the console to write a whole program. Indent a line (begin it with spaces) and Sheerpower collects it into a program instead of running it immediately — and that includes whole multi-line, multi-statement constructs: indent a for loop, an if block, or a routine and every indented line is added to the program, structure and all. Keep indenting to build it up; then a bare run runs it:

Show me: building a program by indenting, appending, and its life cycle
>>> for i = 1 to 10 >>> print i >>> next i >>> run C:\Sheerpower\MyProgram.spsrc 1 2 3 4 5 6 7 8 9 10 >>>

And it appends as you go. Run it, try a few things at the prompt, then indent another block — the new block is added to the end of the program, not put in place of what was there. So a program grows a piece at a time, in whatever order the pieces occur to you, and edit is there when you want to reorder or remove one.

>>> print 'first' >>> run C:\Sheerpower\MyProgram.spsrc first >>> print 'second' ← a second indented block, entered later >>> run C:\Sheerpower\MyProgram.spsrc first ← both blocks now run, in order second >>>

What you have built this way is a real, editable program, and the console gives you its whole life cycle:

  • edit — hands the program you have built to the Sheerpower IDE for full, free-form editing, validated as you go. When you leave the IDE, the edited program is reloaded into the console — usually in under half a second, even for large programs — and you are back at the >>> prompt, right where you left off, ready to run it or keep working;
  • save 'name' — writes it out to a file;
  • build 'name' — compiles and deploys it as a .sprun image;
  • run — runs what you have written; run 'name' runs a saved program (see the next section).

In many interactive prompts, what builds up as you type is a playground of live values and definitions — handy for trying an idea out, but you cannot really see it as a program, and it cannot become a finished application; you experiment at the prompt and write the real code somewhere else. Here, what you build up is real source: you can look at it and rearrange it (edit), keep it (save 'name'), and turn it into a deployable application (build 'name'). So the session is not a throwaway scratchpad — it is the start of a real program, and edit takes it into the full IDE when it outgrows the prompt.

Worth knowing: where the console really stands out is debugging a running program: halt it, inspect and change values, single-step, then continue. That live, in-place debugging is more integrated than the tooling most languages give you out of the box.

Running a Saved Program from the Console

A program you have saved in a file is run from the console with run followed by the file's path in quotes. The .spsrc file type is the default, so it can be left off; a logical name that points at a folder works too (run 'sptests:hello'). The program is compiled first and then run; its output appears in the console, and when it ends you are back at the >>> prompt with every variable still available for inspection.

Show me: running a saved program and inspecting its variables after

Say c:\work\hello.spsrc holds this small, correct program:

greeting$ = "Hello, world!" print greeting$ end

Because it compiles cleanly, it runs, prints its output, and leaves you at the prompt — where its variables are still set, so you can inspect them:

>>> run 'c:\work\hello' Hello, world! >>> print greeting$ Hello, world! >>>

Running a Deployed (.sprun) Program

The run command runs your saved source (a .spsrc file). When a program is ready to hand to other people, you deploy it: sp4gl myprog /build (or Deploy in SPDEV, F6 in Visual Studio Code) compiles it and writes a .sprun file — a portable, encrypted image that runs exactly the same but keeps your source code hidden. You run a .sprun the same way; just include the .sprun on the name, since .spsrc is what run assumes:

Show me: running a .sprun, and shipping without Sheerpower installed
>>> run 'c:\work\hello.sprun' Hello, world! >>>

Note: Deploying is covered in full in its own section. To ship a program to someone with no Sheerpower installed, put the .sprun beside a renamed copy of sp4gl.exe (for example MyProg.exe) — running that .exe runs the deployed program. See Building and Deploying.

When a saved program has mistakes, the same run reports them and does not run — that is the next section.

How Compile-Time Errors Are Reported

If the program has mistakes, it does not run. Each mistake is shown as a block: the message, an arrow to the line and column, the source line with its line number in the gutter, a caret under the offending token, and a labelled explanation — Help>> for what went wrong, Format>> for the statement's correct shape and Fix>> for what to do. The blocks are listed in line order. Suppose c:\work\broken.spsrc holds:

Show me: an error listing, the ENTER-to-edit offer, and cascades
dim grid(2 3), other(4) print other(1) prnt "hello" select cse x end

>>> run 'c:\work\broken' | ?? Syntax error | --> line 2, col 12 | 2 | dim grid(2 3), other(4) | ^ | Help>> DIM name() expects a closing ')' | also: other undeclared at line 3 -- follows the error at line 2 | ?? Unrecognized statement | --> line 4, col 1 | 4 | prnt "hello" | ^ | Help>> a statement that starts with a name is an assignment, so = | was expected here, found 'hello' -- if the name was meant as | a keyword, check its spelling | ?? Unrecognized keyword | --> line 5, col 8 | 5 | select cse x | ^ | Format>> select case expr | | Fix>> SELECT must be followed by CASE 3 errors, first at line 2, plus 1 that follows from them -- correct them to RUN Press ENTER to edit the program. >>>

Because the program did not run, the console offers to fix it: after the errors it prints Press ENTER to edit the program. and waits at the prompt. You read the errors, press ENTER, and Sheerpower opens the program in the editor, ready for you to correct the lines it named. The pause matters — it lets you read the error messages first, so you are never thrown straight into the editor before you can see what was wrong. This offer appears only at the interactive console — a batch or /headless run simply reports the errors and stops.

Two things in that listing are worth knowing. The one-line also: entry is a cascade: other(4) was never declared because its dim line failed, so the later complaint about it is reported as a consequence of the first error rather than as a separate block — fix the dim line and both go away. And the count line at the end tells you where to start: with more than a few errors it says fix the first error first; later ones often follow from it. After ten blocks the rest are only counted; run sp4gl broken /allerrors from the Windows command prompt to see every one.

How an Uncaught Runtime Exception Is Reported

A program that compiles cleanly can still fail while running — a file that is not there, a division by zero, an argument out of range. If nothing in the program catches the exception (see Exception Handling tutorial for when exception in ... use ... end when), the console shows a block of the same shape: the message, the routine and line where it happened, the failing statement, a Detail>> line with the specifics, and a Called>> line for each level of the call stack, innermost first. Suppose c:\work\oops.spsrc holds:

Show me: a runtime-error block and the _error_ file
code = 300 show_it end routine show_it c$ = chr$(code) end routine

>>> run 'c:\work\oops' | ?? Illegal argument to CHR$() | --> SHOW_IT, line 1 | 1 | c$ = chr$(code) | Detail>> chr$(300): the code must be 0..255 | | Called>> from MAIN, line 3: show_it Writing all debug information to... c:\work\oops_error_20260830_045635.txt Done. >>>

The line number is counted within the routine (SHOW_IT, line 1 is the first statement of show_it), and the Called>> line shows the statement in MAIN that called it. Because the program says option abort, it ends and writes an _error_ file that opens with this same block and goes on to list every variable, the open files and the call stack — everything you need to see what the program was doing. Without option abort the block is shown and you are left at the >>> prompt inside the stopped program, exactly as after ALT+B below, where print code would show the 300 that caused it.

Mistakes Typed at the Console

A line typed at the prompt is compiled and run on the spot, so a mistake in it is reported the same way, as a block — there is just no file and no line number, only the line you typed, the caret and the explanation:

Show me: a mistyped console line reported as a block
>>> prnt a/b | ?? Unrecognized statement | | prnt a/b | ^ | Help>> a statement that starts with a name is an assignment, so = | was expected here, found 'a' -- if the name was meant as a | keyword, check its spelling Errors (1) must be corrected to RUN >>>

Nothing is lost: the variables you set earlier are untouched, and the corrected line can be typed straight away.

Interrupting a Running Program

When a Sheerpower program is running in its console window, you might encounter a situation where the program is taking too long to complete, or you suspect it's stuck in an infinite loop. For these moments, Sheerpower provides a powerful built-in debugging feature.

By clicking anywhere in the console window to give it focus and then pressing ALT+B, you can immediately halt the program's execution.

This action does more than just stop the program—it drops you directly into the Sheerpower REPL (Read—Eval—Print Loop) at the exact point where the program was interrupted. The console will display the source file and line number where the halt occurred, giving you immediate context.

From within this interactive state, you can:

Show me: inspect, change, step, resume, and read a routine's variables
  • Inspect a variable: type print variable_name, or the shorthand = variable_name, to see its current value.
  • Evaluate an expression: test a condition or do a calculation with the live data — = balance * rate.
  • Change a variable: assign a new value with variable_name = value, then go — the program runs on with the value you set, so you can try a fix without editing and restarting.
  • See everything: type show all to dump every variable, array, table, and cluster, the open files, and the calling stack, all at once.
  • Step one statement at a time: type step to run the next statement and stop again, or step 5 to run five. The Esc key is a one-tap step; F1 steps over a routine call, and F3 steps out of the current routine. Stepping opens a Program Trace window that logs each statement as it runs; trace off stops it as does closing the trace window.
  • Resume execution: type go to let the program proceed from where it left off.
  • Stop execution: type stop to end the program completely, or simply close the window.

The names you reach this way are the program's module variables. To read a routine's parameters or its private variables, prefix the name with the routine's own name and a $. Given routine do_taxes with rate, the parameter rate is do_taxes$rate at the halted console — you can print it and change it just like any other variable:

BREAK at DO_TAXES.4 >>> = do_taxes$rate ← a routine parameter: routine-name $ variable .0275 >>> do_taxes$rate = 0.03 ← change it >>> go ← continue, now with rate = .03

Instead of running straight on with go, you can walk the program one statement at a time. Type step to run the next statement and stop again, or step 5 to run five in a row; tapping Esc is the same as step then Enter, so you can rest a finger on it and watch the program advance. When the next statement is a routine call, two function keys refine the step: F1 steps over the call — it runs the whole routine at full speed and stops on the line after — and F3 steps out of the routine you are in, running to its return and stopping back in the caller. Stepping opens a Program Trace window that lists each statement as it runs — the time, its MAIN.line label, and the source text — so you see exactly the path the program takes. Type trace off when you are done to close it.

BREAK at MAIN.4 >>> step ← run the next statement, stop again (Esc does the same) >>> step >>> step 5 ← three statements on, the loop printed 5 >>> step 3 ← run three at once 6 >>> trace off ← close the Program Trace window >>> go ← run on normally

Tip: This feature is an invaluable tool for live debugging. It allows you to pause a running application and diagnose its state instantly, without needing to stop and restart it under a separate debugger.
(Show/Hide Sheerpower REPL & ALT+B Debugging Takeaways)
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.