Skip to content

Migrating to Rad v0.8

Version 0.8 removes the get_default function. This guide will help you update your scripts.

Breaking Change: get_default Removed

What Changed

The get_default(map, key, default) function has been removed. Use the ?? fallback operator instead.

Old Syntax (No Longer Works)

// These no longer work:
value = get_default(config, "timeout", 30)
value = config.get_default("timeout", 30)

New Syntax

// Use the ?? operator:
value = config["timeout"] ?? 30
value = config.timeout ?? 30

Migration Steps

  1. Find all uses of get_default in your scripts
  2. Replace with ?? syntax:
  3. get_default(m, "key", val) becomes m["key"] ?? val
  4. m.get_default("key", val) becomes m["key"] ?? val or m.key ?? val

Example 1: Basic Usage

// Before
data = {"name": "Alice"}
name = get_default(data, "name", "Unknown")
city = get_default(data, "city", "Unknown")

// After
data = {"name": "Alice"}
name = data["name"] ?? "Unknown"
city = data["city"] ?? "Unknown"

Example 2: UFCS Style

// Before
state = load_state()
count = state.get_default("count", 0)

// After
state = load_state()
count = state["count"] ?? 0

Example 3: Chained Fallbacks

The ?? operator also supports chaining, which wasn't possible with get_default:

// Try multiple keys, fall back to default
value = config["new_key"] ?? config["old_key"] ?? "default"

Why This Change?

The ?? operator provides the same functionality with several advantages:

  • More concise: m["k"] ?? d vs get_default(m, "k", d)
  • Lazy evaluation: The default value is only evaluated if the key is missing
  • Chainable: Multiple fallbacks can be chained together
  • Familiar: Standard null-coalescing syntax from other languages

Error Messages

If you run a script that still uses get_default, you'll see a helpful error:

Error at L3:1

  get_default(m, "b", 0)
  ^^^^^^^^^^^ Cannot invoke unknown function: get_default

Note: get_default was removed. Use the ?? operator instead:
  Old: get_default(map, "key", default)
  New: map["key"] ?? default

See: https://amterp.github.io/rad/migrations/v0.8/