01 Tutorial — Script engine
Deconstruct tuples in a single Dim — the smallest possible sciBASIC# script.
Every tutorial series starts with a hello-world, and this one happens to be a tuple. One Dim statement pulls (1, 2) apart into two typed variables, an array literal collects three (String, Integer) tuples, and a For Each with inline deconstruction prints them — 45 lines including the banner comments, and your first complete tour of how a sciBASIC# script looks and runs.
02 Pipeline
Tuples in three moves
Deconstruct
Dim (a, b as double) = (1, 2) pulls one tuple apart into two typed variables in a
single Dim statement — a and b become ordinary
Double variables holding 1 and 2.
Collect
dim tuples = {("a", 123), ("b", 456), ("c", 789)} builds an array whose elements are
themselves tuples of (String, Integer).
Iterate
for each (str as string, int) in tuples deconstructs every element while walking the
array — the tuple lands directly in two named loop variables, ready for
$"{str} => {int:F4}" formatting.
01 The Script
Full demo source
The complete script exactly as executed by the sciBASIC# script engine (vbs.exe) — nothing elided.
' ============================================================================
' Tuple tutorial
'
' This script demonstrates tuple support in the VBS (VisualBasic.Scripting)
' language:
' 1) deconstructing a tuple into several named variables in a single
' ``Dim`` statement
' 2) building an array of tuples from a literal
' 3) deconstructing each tuple while iterating it with ``For Each``
'
' Run:
' vbs.exe tutorials\VBS\tuple\tuple.vb
'
' Expected output:
' demo test result of variable tuple deconstruct in vb:
' a := 1
' b := 2
' (a+b) := 3
' a => 123.0000
' b => 456.0000
' c => 789.0000
' ============================================================================
' Deconstruct the tuple ``(1, 2)`` into two typed variables in a single line.
' ``a`` and ``b`` become ordinary Double variables holding 1 and 2.
Dim (a, b as double) = (1, 2)
console.writeline("demo test result of variable tuple deconstruct in vb:")
console.writeLine($"a := {a}")
console.writeLine($"b := {b}")
console.writeLine($"(a+b) := {a + b}")
' An array literal whose elements are tuples of (String, Integer).
dim tuples = {
("a", 123), ("b", 456), ("c", 789)
}
' Each item is deconstructed into a String and an Integer while iterating.
for each (str as string, int) in tuples
call console.writeline($"{str} => {int:F4}")
next
03 Results
The console, verbatim
Run with vbs.exe tuple.vb — the whole session is seven lines long:
demo test result of variable tuple deconstruct in vb:
a := 1
b := 2
(a+b) := 3
a => 123.0000
b => 456.0000
c => 789.0000
.vb file: no Module wrapper, no
Sub Main, no ceremony. Top-level statements execute in order, and this is the smallest runnable
demo of the engine — everything else in the tutorial series builds on exactly this shape.