rl_lang/docs/entries/tutorial/t2/
p_b11.rs1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static ADV_COMMANDS_DONE_REMOVE: ConceptEntry = ConceptEntry {
4 name: "11. done, remove, and clear",
5 summary: "done, remove, and clear",
6 category: ConceptCategory::Tooling,
7 prerequisites: &[],
8 descriptions: &[
9 DescriptionEntry {
10 kind: DescriptionKind::Explanation,
11 title: None,
12 description: "done and remove both take a task ID as their argument. the ID comes in as a string from the command parser. validate it exists before acting - use csv_find_by_id and is_null",
13 examples: &[
14 "get is_null from std::types\nget format from std::str\n\nfn cmd_done(arr[arr[string]] tasks, string id) -> arr[arr[string]] {\n dec arr[string] task = csv_find_by_id(tasks, id)\n if (is_null(task)) {\n println(format(\"no task with id {}\", id))\n return tasks\n }\n tasks = csv_update_field(tasks, id, COL_STATUS, \"done\")\n csv_save(TASKS_FILE, tasks)\n println(format(\"marked task {} as done\", id))\n return tasks\n}",
15 ],
16 expected_output: &[],
17 },
18 DescriptionEntry {
19 kind: DescriptionKind::Explanation,
20 title: None,
21 description: "remove works the same way - find first, then delete. give the user a confirmation message either way so they know what happened",
22 examples: &[
23 "fn cmd_remove(arr[arr[string]] tasks, string id) -> arr[arr[string]] {\n dec arr[string] task = csv_find_by_id(tasks, id)\n if (is_null(task)) {\n println(format(\"no task with id {}\", id))\n return tasks\n }\n tasks = csv_remove_by_id(tasks, id)\n csv_save(TASKS_FILE, tasks)\n println(format(\"removed task {}\", id))\n return tasks\n}",
24 ],
25 expected_output: &[],
26 },
27 DescriptionEntry {
28 kind: DescriptionKind::Explanation,
29 title: None,
30 description: "clear removes all tasks with status done in one pass. arr_filter does the work - keep everything that is not done",
31 examples: &[
32 "fn cmd_clear(arr[arr[string]] tasks) -> arr[arr[string]] {\n dec arr[arr[string]] remaining = csv_filter_by(tasks, COL_STATUS, \"pending\")\n dec int removed = len(tasks) - len(remaining)\n csv_save(TASKS_FILE, remaining)\n println(format(\"cleared {} completed task(s)\", removed))\n return remaining\n}",
33 ],
34 expected_output: &[],
35 },
36 DescriptionEntry {
37 kind: DescriptionKind::Explanation,
38 title: None,
39 description: "exercise: implement done, remove, and clear. wire all five commands into the main loop. test the full flow: add tasks, mark some done, clear them, verify the list\n\nexpected output:\n > done 1\n marked task 1 as done\n > clear\n cleared 1 completed task(s)\n > list\n [2] [pending] 2026-06-20 write tutorial",
40 examples: &[
41 "} else if (cmd == \"done\") {\n if (is_empty(args)) {\n println(\"usage: done <id>\")\n } else {\n tasks = cmd_done(tasks, args)\n }\n} else if (cmd == \"remove\") {\n if (is_empty(args)) {\n println(\"usage: remove <id>\")\n } else {\n tasks = cmd_remove(tasks, args)\n }\n} else if (cmd == \"clear\") {\n tasks = cmd_clear(tasks)\n}",
42 ],
43 expected_output: &[],
44 },
45 ],
46 pitfalls: &[],
47 related: &[],
48 related_stdlib: &[],
49 since: None,
50};