sciBASIC# knot logo sciBASIC#

02 Tutorial — Script engine

Dim is forever, let is fluid — two variable declarations, one shape-shifting value.

Module Scripting · VBS engine Feature strong vs dynamic typing Run vbs.exe dynamic_type.vb Output console

The script engine supports both worlds at once. Dim a As Integer pins a variable to a CLR type for its whole lifetime, while let b = 456 hands the runtime free rein: the same name starts as an Integer, becomes an anonymous object with two addressable fields, and ends as a Boolean. Fifty-one lines show exactly where each style fits.

02 Pipeline

Two declaration styles, one variable that shape-shifts

Step 1

Declare

Dim a As Integer is a CLR strong-typed variable — the declared type is fixed for the whole lifetime of the variable, and assigning anything else would fail.

Step 2

Infer

let b = 456 creates a CLR dynamic/weak-typed variable: the runtime infers the type from the assigned value and infers it again on every new assignment.

Step 3

Re-infer

b = new with {.a = 123, .b = 456} re-infers b as an anonymous type whose two fields are exposed directly (b.a, b.b); one more assignment turns it into a Boolean.

01 The Script

Full demo source

The complete script exactly as executed by the sciBASIC# script engine (vbs.exe) — nothing elided.

dynamic_type.vb · 51 linesDownload dynamic_type.vb
' ============================================================================
'  Dynamic type tutorial
'
'  This script demonstrates the two variable declarations available in the VBS
'  (VisualBasic.Scripting) language and how a dynamically typed variable can be
'  reassigned to values of different shapes at runtime.
'
'      Dim a As Integer  -> a CLR strong-typed variable; the declared type is
'                           fixed for the whole lifetime of the variable
'      let b = 456       -> a CLR dynamic/weak-typed variable; the runtime
'                           infers the type from the assigned value and infers
'                           it again on every new assignment
'
'  Run:
'      vbs.exe tutorials\VBS\dynamic_type\dynamic_type.vb
'
'  Expected output:
'      a := 123
'      b := 456
'      b.a := 123
'      b.b := 456
'      check boolean := False
' ============================================================================

' Declare a CLR strong-typed variable with ``Dim`` in the Visual Basic language.
' The variable is permanently an Integer, so a value of another type would fail.

Dim a as integer
a = 123
console.writeline($"a := {a}")

' Declare a CLR dynamic/weak-typed variable with ``let`` in the Visual Basic
' language. Here ``b`` starts as an Integer, is then reassigned to an anonymous
' object and finally to a Boolean -- its runtime type follows the assigned value.

let b = 456
console.writeline($"b := {b}")

' ``b`` is re-inferred as an anonymous type with two fields (a and b).
' The dynamic variable exposes those fields directly.

b = new with {.a = 123, .b = 456}

console.writeline($"b.a := {b.a}")
console.writeline($"b.b := {b.b}")

' ``b`` is re-inferred once more, this time as a Boolean.

b = false

console.writeline($"check boolean := {b}")

03 Results

The console, verbatim

The same name b prints as a number, as two anonymous-object fields, and finally as a Boolean — each line a different runtime type:

dynamic_type.vb — console output
a := 123
b := 456
b.a := 123
b.b := 456
check boolean := False
This is the same engine that powers every other tutorial — the data-science scripts lean on dynamic typing to pass tables, models and entities around without ceremony, while Dim keeps hot numeric loops fully strong-typed.