Index.walk: def of bolt@1.27.0.0 Import: import bolt@1.27.0.0/src/rules/pedantic/index.bend as Index Lines 43-65 of bolt@1.27.0.0/src/rules/pedantic/index.bend: https://jend.leeeet.dev/read.txt?path=bolt@1.27.0.0/src/rules/pedantic/index.bend&start_line=43&end_line=65 import Base import bolt@1.27.0.0/src/finding.bend as F import bolt@1.27.0.0/src/syntax/lex.bend as Lex import bolt@1.27.0.0/src/syntax/tree.bend as Tree import bolt@1.27.0.0/src/rules/calls.bend as Calls # every List.get / String.get call at a computed index, but self's own def walk(nn: Tree.Node, +path: String, +fixed: List<&2, String>, +self: String) -> List<&2, F.Finding>: match nn: case Tree.NCons{Tree.Leaf{Lex.Tok{k, +t, +l, +c}}, Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, +kids, _}, rest}}: +list = named(t, self, "List.get") +as = Calls.args(kids) +get = Bool.and(String.eq(o, "("), Bool.or(list, named(t, self, "String.get"))) +fire = Bool.and(get, Bool.and(Bool.not(literal(Calls.arg(as, Bool.pick(Nat, list, 3n, 1n)))), Bool.not(held(list, Calls.arg(as, 2n), fixed)))) +more = List.concat(&2, F.Finding, [walk(kids, path, fixed, self), walk(rest, path, fixed, self)]) Bool.pick(List<&2, F.Finding>, fire, F.Finding{path, l, c, U32.from_nat(String.length(t)), "index", t ++ " in a recursive def walks the list from its head on every step, which is quadratic; recurse over the list itself."} <> more, more) case Tree.NCons{Tree.Group{open, +kids, close}, rest}: List.concat(&2, F.Finding, [walk(kids, path, fixed, self), walk(rest, path, fixed, self)]) case Tree.NCons{Tree.Stmt{kind, +kids, body}, rest}: List.concat(&2, F.Finding, [walk(kids, path, fixed, self), walk(body, path, fixed, self), walk(rest, path, fixed, self)]) case Tree.NCons{h, rest}: walk(rest, path, fixed, self) case other: Nil{} Uses (20): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.not https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.or https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.concat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.eq https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.length https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.from_nat https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/finding.bend&name=Finding https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/calls.bend&name=arg https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/calls.bend&name=args https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/pedantic/index.bend&name=held https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/pedantic/index.bend&name=literal https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/pedantic/index.bend&name=named https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/syntax/lex.bend&name=Tok https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/syntax/tree.bend&name=Node