D/BASIC quick reference¶
Use this chapter when you remember the idea but not the spelling. The teaching and edge cases live in the linked chapters.
Source rules¶
| Construct | Form |
|---|---|
| statement end | newline |
| statement separator | : |
| numbered line | 10 statement |
| named label | Name: |
| comment | ' text or REM text |
| name case | ASCII case-insensitive |
| identifier | letter, then letters/digits/_; dotted components allowed |
| name length | 40 characters per dotted component |
| string literal | "text", maximum 32,767 bytes |
| decimal integer / real | 42, 3.5, .625 |
| exponent | 1.2E6 (SINGLE) or 1.2D30 (DOUBLE) |
| literal suffix | %, &, @, !, # forces the numeric type |
| hex literal | &HFF |
| octal literal | &O377 or classic &377 |
Whitespace separates keywords from names. FOR I is two tokens; FORI is one identifier.
Types¶
| Type | Suffix | Width/shape |
|---|---|---|
INTEGER |
% |
signed 16-bit |
LONG |
& |
signed 32-bit |
DECIMAL |
@ |
signed 64-bit fixed point, four fractional digits |
SINGLE |
! |
IEEE binary32; default numeric type |
DOUBLE |
# |
IEEE binary64 |
STRING |
$ |
counted variable-length text |
STRING * n |
— | fixed-width record field, 1..65535 bytes |
named TYPE |
— | inline value record |
named CLASS |
— | counted object reference |
Numeric widening: INTEGER → LONG → DECIMAL → SINGLE → DOUBLE.
False is 0; true is -1.
Declarations and storage¶
| Purpose | Syntax |
|---|---|
| scalar | DIM Name [AS Type] |
| several names | DIM A AS INTEGER, B AS LONG |
| array | DIM A(upper) [AS Type] |
| explicit array bounds | DIM A(lower TO upper [, ...]) [AS Type] |
| implicit array | first undeclared A(index [, ...]) creates each dimension as OPTION BASE TO 10 |
| module shared | DIM SHARED Name [AS Type] |
| module shared array | DIM SHARED A(bounds) [AS Type] |
| procedure shared alias | SHARED Name [AS Type] [, ...] or SHARED A() [AS Type] [, ...] |
| persistent local | STATIC Name [AS Type] [, ...] |
| persistent whole-array local | STATIC A() [AS Type] |
| resize | REDIM [PRESERVE] A(bounds) [AS Type] |
| release array | ERASE A [, B...] |
| constant | CONST Name = value [, Name = value...] |
| default type ranges | DEFINT letter[-letter] [, ...] (also DEFLNG, DEFSNG, DEFDBL, DEFSTR) |
| default lower bound | OPTION BASE 0 or OPTION BASE 1 |
| RAM-only memory ceiling | OPTION TIER RAM |
REDIM PRESERVE is refused for an array of TYPE records; ordinary REDIM may replace that array atomically.
See Variables, DIM & Memory for initialization, scope, lifetime, arrays, and the difference between declaring a binding and constructing an object.
Assignment¶
[LET] destination = expression
SET objectDestination = expression
property += expression
SWAP left, right
MID$(target$, start [, length]) = replacement$
SET is an optional object-assignment spelling. += is the compound property operation. SWAP exchanges compatible scalar/record locations. The MID$ lvalue overwrites an existing string slice; it is distinct from the MID$() expression.
Decisions¶
SELECT CASE expression
CASE value [, value...]
CASE low TO high
CASE IS relation value
CASE ELSE
END SELECT
Loops¶
Exits: EXIT FOR, EXIT WHILE, EXIT DO, EXIT SUB, EXIT FUNCTION.
Classic branches¶
| Statement | Syntax |
|---|---|
| jump | GOTO target |
| subroutine | GOSUB target |
| return | RETURN |
| computed jump | ON expression GOTO target [, ...] |
| computed subroutine | ON expression GOSUB target [, ...] |
| refusal handler | ON REFUSAL GOTO target |
| refusal fields | ERR, ERL |
| continue after refusal | RESUME NEXT |
| resume at target | RESUME target |
A target is a numbered line or named label.
ERR is the refusal rule and ERL is the source line. Compile and load refusals happen before execution and cannot be caught inside the program; ON REFUSAL handles runtime operation refusals. See Errors, Refusals & Diagnostics.
Procedures¶
Scalar/record/object parameter:
Whole-array parameter:
SUB, FUNCTION, and method parameters default to BYREF. At a call site, BYVAL X or classic extra parentheses (X) force a scalar/record/object value. Whole arrays pass as descriptors and cannot be BYVAL. WEAK is legal only on an object instance field, never on a parameter.
| Argument kind | BYVAL |
BYREF |
|---|---|---|
| numeric scalar | copies the value | aliases the caller's variable |
STRING |
copies the string value | aliases the caller's string binding |
TYPE record |
copies the complete record | aliases the caller's record |
CLASS reference |
copies the reference; both references may reach the same object | aliases the caller's reference binding, so the callee may replace it |
whole array A() |
forbidden | shares the array binding and its elements |
Calls:
Expression function:
DEF FN parameters are value copies, independent of the regular procedure BYREF default.
See Procedures & Functions for call-site overrides and worked examples.
Strings and text¶
| Purpose | Form |
|---|---|
| concatenate | left$ + right$ |
| length in bytes | LEN(text$) |
| prefix / suffix / slice | LEFT$(text$, n), RIGHT$(text$, n), MID$(text$, start [, count]) |
| find a substring | INSTR([start,] text$, sought$) |
| repeat a string / byte | STRING$(count, text$) or STRING$(count, code) |
| spaces | SPACE$(count) |
| change case | LCASE$(text$), UCASE$(text$) |
| trim edges | LTRIM$(text$), RTRIM$(text$) |
| byte/code conversion | ASC(text$), CHR$(code) |
| number to text | STR$(number) |
| text to number | VAL(text$) |
| fixed-width field | Field AS STRING * n inside a TYPE |
String positions and lengths are byte-based. See Strings & Text for clamping rules, UTF-8 boundaries, conversion behavior, and writable MID$ slices.
Arrays¶
| Operation | Syntax |
|---|---|
| element | A(index [, ...]) |
| first bound | LBOUND(A [, dimension]) |
| last bound | UBOUND(A [, dimension]) |
| independent copy | ARRAYCOPY Source() TO Destination() |
| uniform fill | ARRAYFILL Destination(), Value |
| binding exchange | ARRAYSWAP A(), B() |
Whole-array verbs require the exact bare A() form. See Arrays.
Their element domain is numeric scalars, variable STRING, and CLASS references; TYPE record arrays are excluded.
Console and program data¶
| Purpose | Syntax |
|---|---|
| output | PRINT [items] |
| zones | PRINT A, B |
| concatenate/suppress newline | PRINT A; B; |
| column | PRINT TAB(n); value |
| spaces | PRINT SPC(n); value |
| formatted numeric | PRINT USING "one numeric field"; value |
| converted input | INPUT ["prompt" {; | ,}] target [, ...] |
| whole line | LINE INPUT ["prompt" {; | ,}] target$ |
| embedded values | DATA value [, ...] |
| consume values | READ target [, ...] |
| rewind data | RESTORE [target] |
| random seed | RANDOMIZE [expression] |
| complete | END (status 0) |
| interrupt | STOP (status 3) |
| raise governed error | ERROR literalRuleId (1..65535) |
The DATA statement above is a table compiled into the program. It is unrelated to the database-oriented DATA Intent domain below.
ERROR requires a literal, and syntax acceptance does not allocate the number. Shipping rule IDs must come from D/BASIC's governed rule register; 61440..65534 is private/experimental and must not ship, 0 means no refusal, and 65535 is never allocated. See Errors, Refusals & Diagnostics.
Files and file manipulation¶
| FILE Intent | Purpose |
|---|---|
FILE.QUERY_MOUNT |
inspect one requested mount and read its capabilities, state, limits, latency class, and mount count |
FILE.LIST |
fetch a bounded, filtered directory page and its generation |
FILE.STAT |
inspect kind, size, flags, and containing-directory generation |
FILE.OPEN |
open for READ, staged CREATE, APPEND, or staged REPLACE |
FILE.READ |
read a bounded byte span at an explicit offset |
FILE.WRITE |
write a bounded byte span at an explicit offset and report progress |
FILE.CLOSE |
close a read handle, commit a staged write atomically, or abandon it |
FILE.EDIT |
DELETE, TRASH, RESTORE, RENAME, same-mount MOVE, or MKDIR |
FILE is bytes at a name. Cross-mount move is deliberately copy-then-delete, not counterfeit atomicity. See Files & File Manipulation.
Database and DATA Intents¶
| DATA family | Operations |
|---|---|
| capabilities and values | QUERY_CAPS, OPEN, GET_VALUE, CLOSE |
| immutable query snapshots | OPEN_SNAPSHOT, FETCH_PAGE, RESOLVE_ROW, REVALIDATE_OBJECT, ACCEPT_EXACT, CLOSE_SNAPSHOT |
| database writes and attachments | QUERY_WRITE_CAPS, OPEN_WRITE, BEGIN_WRITE, BEGIN_ATTACHMENT, WRITE_ATTACHMENT_CHUNK, FINISH_ATTACHMENT, COMMIT_WRITE, WRITE_STATUS, ABORT_WRITE, CLOSE_WRITE |
| durable artifact writes | QUERY_ARTIFACT_CAPS, BEGIN_NEW, BEGIN_SAVE, BEGIN_SAVE_AS, BEGIN_PUBLISH, WRITE_ARTIFACT_CHUNK, FINISH_ARTIFACT, COMMIT_ARTIFACT, ARTIFACT_STATUS, ABORT_ARTIFACT, CLOSE_ARTIFACT, ACK_ARTIFACT_RECEIPT |
| artifact retirement and reads | BEGIN_RETIRE, ALLOCATE_ARTIFACT_OPERATION, LIST_ARTIFACTS, OPEN_ARTIFACT_READ, READ_ARTIFACT_CHUNK, CLOSE_ARTIFACT_READ, LIST_PUBLICATIONS, OPEN_PUBLICATION_READ |
DATA is a revision of an identity. Sessions and snapshots are owner/run-bound. Database-write transactions finish with a terminal outcome/status; durable artifact mutation adds an exact receipt and acknowledgement. Neither becomes durable merely because a button was pressed. See Database & Data Intents.
Snapshot filters are ALL, CLASS, COLLECTION, REFERENCES, and PROPERTY_EQUALS. Semantic values include Boolean, integer, decimal/money/percentage, text/bytes, date/time/date-time/duration, enum/quantity, resource/reference/Works link, and a bounded multiple value.
Program faces¶
| Source shape | Derived face |
|---|---|
| no window lifecycle or input handlers | console |
| window handlers, no top-level executable statements | windowed |
| top-level executable statements and window handlers | console + windowed; launch surface selects |
The two faces share procedures, objects, arrays, imports, and one DBC image. Console programs run top-level statements in sequence; window programs run through host-dispatched lifecycle and event turns. See Console, Scripts & GUI.
Records¶
TYPE Name
NumericField% | NumericField AS NumericType
FixedText AS STRING * n
Nested AS OtherRecordType
END TYPE
Member access: record.Field. Record assignment copies the value. A TYPE is a closed, acyclic value graph: array, variable STRING, CLASS, handle/resource, and WEAK fields are not permitted. Arrays of records are legal.
Classes¶
CLASS Name [EXTENDS Base]
[PUBLIC: | PROTECTED: | PRIVATE:]
[STATIC] Field% | [STATIC] Field AS Type
WEAK ObjectField AS SomeClass
DECLARE SUB Method (...) [VIRTUAL | ABSTRACT | OVERRIDE]
DECLARE FUNCTION Method (...) [AS Type] [VIRTUAL | ABSTRACT | OVERRIDE]
DECLARE CONSTRUCTOR (...)
DECLARE DESTRUCTOR
DECLARE PROPERTY Name (...) [AS Type]
END CLASS
Bodies:
SUB ClassName.Method (...) ... END SUB
FUNCTION ClassName.Method (...) [AS Type] ... END FUNCTION
CONSTRUCTOR ClassName (...) ... END CONSTRUCTOR
DESTRUCTOR ClassName ... END DESTRUCTOR
PROPERTY ClassName.Name (...) [AS Type] ... END PROPERTY
Object expressions:
| Form | Meaning |
|---|---|
NEW ClassName(arguments) |
construct object |
NOTHING |
empty object reference |
THIS |
current member receiver |
A IS B |
same object identity |
TYPEOF(A) IS ClassName |
class-shape test |
BASE(arguments) is a constructor-body statement that calls the selected base constructor; it is not an object expression.
Class fields may be numeric, dynamic STRING, inline TYPE, or strong/weak object references. Arrays and host resource/handle values are not class fields. WEAK applies only to an object instance field and cannot combine with STATIC.
Normal use forms are Object.Field, Object.Method(arguments), Object.Property or Object.Property(index), and ClassName.StaticField.
Window faces¶
| Face | Signature |
|---|---|
| open | WINDOW SUB OPEN() |
| draw | WINDOW SUB DRAW() |
| resize | WINDOW SUB RESIZE(W AS INTEGER, H AS INTEGER) |
| close | WINDOW SUB CLOSE() |
| active | WINDOW SUB ACTIVE(State AS INTEGER) |
| visible | WINDOW SUB VISIBLE(State AS INTEGER) |
| suspended | WINDOW SUB SUSPENDED(State AS INTEGER) |
| minimized | WINDOW SUB MINIMIZED(State AS INTEGER) |
| maximized | WINDOW SUB MAXIMIZED(State AS INTEGER) |
| key | ON KEY SUB (K AS INTEGER) |
| pointer | ON POINTER SUB (X AS INTEGER, Y AS INTEGER, Buttons AS INTEGER) |
| menu command | ON MENU SUB (ID AS INTEGER) |
| unified event | IMPORT WIDGETS plus ON EVENT SUB (E AS UIEVENT) |
| accepted drop types | WINDOW ACCEPTS "DOBJ", "STYL", "TEXT" |
| drop | ON DROP SUB (D AS DROPITEM) |
Every window program has one OPEN, DRAW, and CLOSE. Other faces are optional and unique.
ON EVENT is mutually exclusive with ON KEY, ON POINTER, and ON MENU; lifecycle faces remain alongside it. Key events describe physical/logical key state but never insert text. TextCommit is the text-insertion event.
Start a drag with DRAG value. Structured TYPE and CLASS values use their governed DOBJ mapping. See Drag, Drop & DOBJ.
DROPITEM fields:
| Field | Value |
|---|---|
KIND$ |
accepted TEXT, STYL, PATH, FILE, or DOBJ tag |
TEXT$ |
complete accepted plain text |
PATH$ |
governed path/reference |
HANDLE |
opaque callback-scoped lease for a typed structured/binary reader |
Outward calls¶
The compiler resolves names, arity, and types from generated registries. See Intents & Services.
Common window calls:
SERVICE SET_TITLE("Title")
SERVICE INVALIDATE()
INTENT GFX.BEGIN_FRAME()
INTENT GFX.SET_CLIP(X, Y, W, H)
INTENT GFX.FILL_RECT(X, Y, W, H, Color)
INTENT GFX.DRAW_TEXT(X, Y, Text$, Font, Foreground, Background)
INTENT GFX.RESET_CLIP()
INTENT GFX.PRESENT()
Application contract¶
APP "NAME"
LABEL "Human label"
ICON 24 "icon24.dic"
ICON 16 "icon16.dic"
NEEDS GFX, FILES, DATA, NETWORK, SOUND
END APP
NEEDS is capability preflight. A package/launcher refuses a required face or capability before execution rather than presenting a half-working application.
Resources and audio¶
| Surface | Purpose |
|---|---|
LOADRESOURCE |
runner operation used by an owning D/Works adapter to resolve a validated package identity |
GFX.BLIT_RESOURCE |
draw a bounded caller-array raster; distinct from a packaged asset |
AUDIO.QUERY_CAPS |
discover voices, waveforms, rates, latency, and limits |
AUDIO.NOTE_ON, NOTE_OFF |
start/replace or stop an app-scoped tone voice |
AUDIO.PROGRAM, VOLUME, SILENCE |
control app-scoped tone presentation |
AUDIO.PCM_OPEN, WRITE, START, STOP, CLOSE, STATS |
run an exact-rate PCM stream lifecycle |
See Resources, Images & Sound.
Gaming & GX¶
| Group | Currently admitted GX core surface |
|---|---|
| scene | GXSceneOpen, GXSceneAdvance, GXSceneReady, GXCarrierWords |
| entities | GXEntityCapacity, GXEntityValid, GXEntitySpawn, GXEntityVelocity, GXEntityStep, GXEntityX, GXEntityY |
| collision | GXRectOverlap, GXEntitiesOverlap |
| tiles | GXTileIndex, GXTileSet, GXTileAt |
| camera | GXCameraFollow, GXCameraX, GXCameraY |
| animation | GXAnimationFrame |
The currently admitted GX core operates on caller-owned rank-one INTEGER carriers: eight words for a scene, ten words per entity, one word per tile, and two words for a camera. The complete engine also spans rendering, input, resources, and audio through portable Intents. See Gaming & GX, the exact engine reference, and GX on 6502.
Networking¶
| Surface | Purpose |
|---|---|
WorksHttpGetText URL$, Max&, Text$, Reply |
bounded complete text fetch |
WorksHttpGet URL$, Body%(), Reply |
bounded complete binary fetch |
WorksNetworkCapabilities(Caps) |
query independent provider capabilities |
WorksWifiStatus(Status), WorksWifiScan(Results) |
inspect system-owned Wi-Fi state |
WorksSessionOpen, WorksSessionPoll |
begin and advance an owning session adapter |
WorksSessionRead(Session, Chunk%(), Count&, EndOfStream%) |
partial read with EOF reported separately |
WorksSessionWrite(Session, Chunk%(), Offered&, Written&) |
partial write with explicit offered and consumed counts |
WorksSessionResize, WorksSessionDecideHostKey |
terminal resize and explicit SSH trust decision |
WorksSessionCancel, WorksSessionClose |
cancel and idempotently release a session |
See Networking.
Imports¶
IMPORT is a standalone line and defaults to BAKED for every module, including protected dworks.* modules and gx. Write SHARED explicitly when the program must bind an exact installed library artifact. See Imports & Libraries.
Intrinsics A–Z¶
| Function | Arguments | Result / purpose |
|---|---|---|
ABS |
1 | absolute numeric value |
ASC |
1 | character code of first byte |
ATN |
1 | arctangent |
CDBL |
1 | convert to DOUBLE |
CHR$ |
1 | one-character string from code |
CINT |
1 | convert to INTEGER, nearest-even |
CLNG |
1 | convert to LONG, nearest-even |
COS |
1 | cosine |
CSNG |
1 | convert to SINGLE |
ERL |
0 | current numbered source line |
ERR |
0 | current error/refusal number |
EXP |
1 | exponential |
FIX |
1 | truncate toward zero |
INKEY$ |
0 | pending console key or empty string |
INSTR |
2–3 | position of substring, optional start |
INT |
1 | floor toward negative infinity |
LBOUND |
1–2 | array lower bound, optional dimension |
LCASE$ |
1 | lowercase ASCII text |
LEFT$ |
2 | left substring |
LEN |
1 | string byte length or packed TYPE record byte length |
LOG |
1 | natural logarithm |
LTRIM$ |
1 | remove leading ASCII whitespace |
MID$ |
2–3 | middle substring, optional length |
RIGHT$ |
2 | right substring |
RND |
0–1 | next value; zero repeats; negative reseeds |
RTRIM$ |
1 | remove trailing ASCII whitespace |
SGN |
1 | -1, 0, or 1 by numeric sign |
SIN |
1 | sine |
SPACE$ |
1 | string containing spaces |
SQR |
1 | square root |
STR$ |
1 | canonical numeric-to-text conversion |
STRING$ |
2 | repeated character/string construction |
TAN |
1 | tangent |
TIMER |
0 | canonical timer seconds |
UBOUND |
1–2 | array upper bound, optional dimension |
UCASE$ |
1 | uppercase ASCII text |
VAL |
1 | canonical text-to-number conversion |
TAB(n) and SPC(n) are PRINT items rather than general expression functions.
Operators¶
Listed from lower to higher precedence:
Punctuation also used by the grammar: ( ) , ; . @ and +=.
Normalized key values¶
| Key | Value |
|---|---|
| Backspace | 8 |
| Tab | 9 |
| Enter | 13 |
| Escape | 27 |
| Delete | 127 |
| Insert | 256 |
| Arrow Up | 257 |
| Arrow Down | 258 |
| Arrow Left | 259 |
| Arrow Right | 260 |
| Home | 261 |
| End | 262 |
| Page Up | 263 |
| Page Down | 264 |
function key Fn |
0x0120 + n |
Printable ASCII keys use their ASCII values.
D/Works widget entry points¶
| Group | Types |
|---|---|
| policy | WorksTheme, WorksMetrics |
| coordination | WorksSurfaceDamage, WorksLocalEvent |
| base/display | WorksWidget, WorksPanel, WorksLabel |
| controls | WorksButton, WorksTextField, WorksToggle, WorksIconButton, WorksTooltip |
| commands | WorksPopoverFrame, WorksCommandRow, WorksMenuItem, WorksMenu, WorksMenuCascade, WorksStatusStrip |
See the dedicated Widgets chapter for ownership, event, focus, caret, damage, and menu patterns.
Deliberate machine and object boundary¶
PEEK, POKE, WAIT, USR, SYS, VARPTR, DEF SEG, raw pointers, address-of, and pointer arithmetic are recognized and refused. Use values, records, objects, handles, Services, and Intents.
Object identity is similarly deliberate: raw-pointer forms, DELETE, copy constructors, and OPERATOR LET are refused permanently. INTERFACE / IMPLEMENTS, general operator overloads, and checked downcasts are outside the current language contract. Prefer inheritance, virtual methods, properties, TYPEOF, and IS.
Where to look next¶
- Behavior of a construct: use the topical chapter in the left navigation.
- Old listing migration: Compatibility, Migration & Refusals.
- Why a call adapts differently per system: Intents & Services.
- What ships: Bytecode & Delivery.
- A live experiment: D/BASIC Playground.