The 10 traps of Jennifer

Jennifer

The wrong code, what the interpreter really says, and the fix.

November 2026, by @mplx.
Based on Jennifer 0.26.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 18

The ten at a glance

#Trap#Trap
1$ on use, never on a name6strings take slices
2reserved words and _7a range must not run backwards
3habits: +=, ++, &&, //8{ in "..." interpolates
4/ is always a float9arguments are copies
5conditions are bool10no anonymous functions

Plus three bonus traps: shadowing, missing map keys, test overlays.

2 / 18

1. $ on use, never on a name

def $x as int init 5;
io.printf("%d\n", x);
io.printf("%d\n", $MAX);     # MAX is a def const
parse error at trap.j:1:5: drop the `$` here: write `def x` (the `$` is only for use-site references)
runtime error at trap.j:3:19: "x" is a variable; use `$x` to reference it
parse error at trap.j:3:19: constant "MAX" is referenced with `$`; drop the sigil (constants are referenced bare)

Fix: def x as int init 5; then $x; constants bare: MAX.

3 / 18

2. Reserved words and underscores

def list as list of int init [];
func range(from as int, to as int) { return $to - $from; }
def my_var as int init 5;
parse error at trap.j:1:5: expected IDENT after `def`, got LIST ("list") - `list` is a reserved word and cannot be used as a name
parse error at trap.j:1:25: expected IDENT for parameter name, got TO ("to") - `to` is a reserved word and cannot be used as a name
parse error at trap.j:1:5: variable name "my_var" may not contain `_` (use camelCase; `_` is only allowed in constant names)

Fix: items, lo / hi, myVar. Only constants take _: MAX_RETRIES.

4 / 18

3. Habits from other languages

$x += 1;
$x++;
if ($a && true) { }
// a comment
} else if ($n > 1) {
parse error at trap.j:2:5: unexpected token ASSIGN ("=") in expression
parse error at trap.j:2:4: unexpected token PLUS ("+") in expression
parse error at trap.j:2:9: unexpected token BIT_AND ("&") in expression
parse error at trap.j:1:1: unexpected token DIV ("//") in expression
parse error at trap.j:3:40: expected LBRACE to begin block, got IF ("if")

Fix: $x = $x + 1;, and / or / not, # comment, elseif.

5 / 18

4. / is always a float

io.printf("%d\n", 7 / 2);
runtime error at trap.j:2:1: io.printf: `%d` requires int, got float
use io;

io.printf("%d %f\n", 7 // 2, 7 / 2);
3 3.5
6 / 18

5. Conditions are bool

def n as int init 3;
if ($n) { io.printf("yes\n"); }
runtime error at trap.j:3:5: `if` condition must be bool, got int
if ($n != 0) { ... }
if (len($name) > 0) { ... }
if (maps.has($m, "key")) { ... }
7 / 18

6. Strings take slices, not positions

def s as string init "Jennifer";
io.printf("%s\n", $s[0]);
runtime error at trap.j:3:21: cannot index into string
use io;

def s as string init "Jennifer";
for (def i in 0..len($s)) {
    io.printf("%s.", $s[$i..$i + 1]);
}
J.e.n.n.i.f.e.r.
8 / 18

7. A range must not run backwards

def s as string init "ab";
for (def i in 3..len($s)) { io.printf("%d\n", $i); }
runtime error at trap.j:3:15: range lower bound 3 exceeds upper bound 2
if ($start < len($s)) {
    for (def i in $start..len($s)) { ... }
}
9 / 18

8. A { in "..." starts an interpolation

def body as string init "{\"a\": 1}";
def keys as list of string init ["{", "}"];    # len 1: [", "]
lex error at trap.j:2:27: unexpected character '\\'
trap.j:2:36: warning: interpolation slot holding only the string literal `, ` ... [L116]
def body as string init '{"a": 1}';
def keys as list of string init ['{', '}'];
10 / 18

9. Arguments are copies

func addItem(xs as list of int, v as int) {
    $xs[] = $v;
}
def items as list of int init [1];
addItem($items, 2);
io.printf("%d\n", len($items));     # prints 1, no error

Fix: append where the list lives, $items[] = 2;, or return it: $items = addItem($items, 2); with return $xs;

11 / 18

10. No anonymous functions, no closures

def ys as list of int init lists.map($xs,
    func(n as int) { return $n * 2; });
parse error at trap.j:4:5: unexpected token FUNC ("func") in expression
func times(n as int) {
    return $n * $factor;    # $factor is a local of the caller
}
parse error at trap.j:8:17: undefined variable "factor"
12 / 18

The fix for 10: a loop

use io;

func scaled(xs as list of int, factor as int) {
    def out as list of int init [];
    for (def x in $xs) {
        $out[] = $x * $factor;
    }
    return $out;
}

def result as list of int init scaled([1, 2], 3);
io.printf("{$result}\n");
[3, 6]
13 / 18

Bonus: no shadowing, one namespace

def i as int init 0;
func count() {
    for (def i in 0..3) { io.printf("%d\n", $i); }
}
def total as int init 0;
func total() { return 1; }
parse error at trap.j:4:5: for-each iterator "i" shadows an enclosing binding
parse error at trap.j:3:1: function "total" shares its name with a top-level variable or constant
14 / 18

Bonus: a missing map key throws

def m as map of string to int init {"a": 1};
io.printf("%d\n", $m["b"]);
runtime error at trap.j:3:21: map has no entry for key b
if (maps.has($m, "b")) { io.printf("%d\n", $m["b"]); }
15 / 18

Bonus: a test overlay is the module

# cart_test.j, beside cart.j which defines parseQty
func parseQty(text as string) {     # a fake for the test
    return 1;
}
cart_test.j: setting up test file: parse error at cart_test.j:3:1: function
  "parseQty" is defined more than once (first defined at cart.j:9:8)
16 / 18

Let the tools find them first

TrapFound by
sigils, names, keywords, habits, closures, shadowingjennifer lint: L002, and L108 for a bare x
["{", "}"]jennifer lint (L116)
a returned, mutated parameterjennifer lint (L205, info)
/ with %d, truthiness, string index, ranges, map keysonly when the line runs: write a test
a helper changing its own copya test that checks the caller's value
17 / 18

Read more

Based on Jennifer 0.26.0, November 2026.

18 / 18