English {#english}
Sprint 7 Review: Generics.Collections
Mintlify docs tour — after Sprint 4 exceptions, Sprint 7 brings the collections every Horse API and CRUD service needs.
Generic containers are not syntactic sugar in Delphi — they are how you build caches, registries, and JSON maps. Sprint 7 (v2.15.0) shipped System.Generics.Collections with working TDictionary<K,V> and TList<T>, including TryGetValue with proper var write-back.
What the review documents
From Sprint 7 Review:
-
varparameters —Value::Reference, write-back in procedures/functions andTryGetValue. -
TDictionary::Add/TryGetValue— dispatch insimulate_function_execution; direct routing for instantiated generics. -
Parser — generic types with
Integer/Stringin expressions (TDictionary<String,Integer>). -
RTL —
rtl/sys/System.Generics.Collections.pas; semantic layer recognizesGenerics.Collections. -
Tests —
generics_collections.rsplus fixtures.
Tag v2.15.0 approved.
Dictionary pattern in production code
program DictDemo;
uses
System.SysUtils,
System.Generics.Collections;
var
D: TDictionary<string, Integer>;
V: Integer;
begin
D := TDictionary<string, Integer>.Create;
try
D.Add('apples', 3);
if D.TryGetValue('apples', V) then
WriteLn('apples = ', V);
finally
D.Free;
end;
end.
TryGetValue only writes V when the key exists — the Delphi idiom you expect in services and controllers.
Why var was the sprint's hidden hero
Before v2.15.0, incomplete var semantics blocked realistic APIs. TryGetValue requires the callee to mutate the caller's variable through a reference. CrabPascal introduced Value::Reference and write-back in procedure dispatch specifically for this surface.
Three implementation lessons from the retrospective:
-
D := TDictionary<...>.Createneedsnormalize_call_nameinexecute_assignment— not just in direct calls. -
Generic instance methods must hit intrinsics before empty VMT lookups — otherwise
Addsilently fails. -
Explicit
outin parser remains debt —varcoversTryGetValuefor now; Sprint 11 later addsouttoken support.
Validation commands
cargo test --test generics_collections
crab-pascal run tests/fixtures/dict_trygetvalue_var.pas
The fixture name tells the story: without var write-back, dictionary lookups lie.
TList quick path
var
L: TList<string>;
begin
L := TList<string>.Create;
try
L.Add('first');
L.Add('second');
WriteLn(L[0]);
finally
L.Free;
end;
end.
Enumerators and for..in over generics remain Sprint 15 territory — documented honestly in the technical debt backlog.
Connection to CRUD and Horse
The examples/crud/ project maps product IDs to records. Sprint 17 (currently in progress) extends this with ProdutoService.pas and JSON — but Sprint 7 laid the dictionary foundation every service layer builds on.
Docs: Mintlify Roadmap → Sprint 7 Review · Release v2.15.0. Next: Sprint 10 and Delphi strings in C codegen — where run vs build parity gets measurable.
Português {#portugus}
Review Sprint 7: Generics.Collections
Tour Mintlify — depois das exceções do Sprint 4, o Sprint 7 traz as coleções que toda API Horse e serviço CRUD precisa.
Containers genéricos não são açúcar sintático em Delphi — são como você monta caches, registros e mapas JSON. O Sprint 7 (v2.15.0) entregou System.Generics.Collections com TDictionary<K,V> e TList<T> funcionais, incluindo TryGetValue com write-back var correto.
O que o review documenta
Do Sprint 7 Review:
-
Parâmetros
var—Value::Reference, write-back em procedures/functions eTryGetValue. -
TDictionary::Add/TryGetValue— dispatch emsimulate_function_execution; roteamento direto para genéricos instanciados. -
Parser — tipos genéricos com
Integer/Stringem expressões (TDictionary<String,Integer>). -
RTL —
rtl/sys/System.Generics.Collections.pas; semântica reconheceGenerics.Collections. -
Testes —
generics_collections.rs+ fixtures.
Tag v2.15.0 aprovada.
Padrão dictionary em código de produção
program DictDemo;
uses
System.SysUtils,
System.Generics.Collections;
var
D: TDictionary<string, Integer>;
V: Integer;
begin
D := TDictionary<string, Integer>.Create;
try
D.Add('apples', 3);
if D.TryGetValue('apples', V) then
WriteLn('apples = ', V);
finally
D.Free;
end;
end.
TryGetValue só escreve em V quando a chave existe — o idioma Delphi esperado em services e controllers.
Por que var foi o herói oculto do sprint
Antes do v2.15.0, semântica var incompleta bloqueava APIs realistas. TryGetValue exige que o callee mute a variável do caller por referência. O CrabPascal introduziu Value::Reference e write-back no dispatch de procedures especificamente para essa superfície.
Três lições da retrospectiva:
-
D := TDictionary<...>.Createexigenormalize_call_nameemexecute_assignment— não só em chamadas diretas. -
Métodos de instância genéricos devem ir para intrinsics antes da VMT vazia — senão
Addfalha silenciosamente. -
outexplícito no parser permanece débito —varcobreTryGetValuepor ora; Sprint 11 adiciona tokenout.
Comandos de validação
cargo test --test generics_collections
crab-pascal run tests/fixtures/dict_trygetvalue_var.pas
O nome da fixture conta a história: sem write-back var, lookups de dictionary mentem.
Caminho rápido com TList
var
L: TList<string>;
begin
L := TList<string>.Create;
try
L.Add('first');
L.Add('second');
WriteLn(L[0]);
finally
L.Free;
end;
end.
Enumerators e for..in sobre genéricos ficam para o Sprint 15 — documentado honestamente no backlog de débito técnico.
Conexão com CRUD e Horse
O projeto examples/crud/ mapeia IDs de produto a records. O Sprint 17 (em andamento) estende com ProdutoService.pas e JSON — mas o Sprint 7 lançou a base de dictionary que toda camada de serviço usa.
Docs: Mintlify Roadmap → Sprint 7 Review · Release v2.15.0. Próximo: Sprint 10 e strings Delphi no codegen C — onde a paridade run vs build fica mensurável.
Published on dev.to/@crabpascal · Código em CrabPascal
Top comments (0)