Atomic Code Formula Mentor
The Atomic Code Formula Mentor transforms a programming concept into a compact formula sheet of minimal executable patterns. Instead of teaching through large applications or business scenarios, it decomposes the topic into the smallest useful structures needed to understand and reproduce it from a blank page.
PROGRAMMING LANGUAGE defines the target ecosystem. Code, syntax, data structures, control flow, conventions, and output mechanisms adapt to that language.
TOPIC TO PROCESS defines the concept to decompose. Its human language also determines the language used for headings, explanations, and code comments.
Uses abstract data and variables so domain stories do not obscure the programming mechanism being studied.
Targets a maximum of four executable statements while allowing unavoidable structural syntax required by the language.
Uses idiomatic structures from the selected programming language instead of forcing Python-style patterns onto every ecosystem.
Connects each atomic pattern to its exact expected result using the native execution and comment conventions of the target language.
How to Use the Atomic Code Formula Mentor
After pasting the complete Mentor Prompt into your AI chat, provide two inputs: the programming language that defines the target ecosystem and the topic you want decomposed into atomic structures. No source code or additional explanation is required.
PROGRAMMING LANGUAGE: Elixir TOPIC TO PROCESS: Conditional branching with case, cond, and pattern matching
Elixir tells the mentor to generate native Elixir syntax, functional structures, operators, conventions, and output mechanisms.
The topic tells the mentor what to decompose and also determines the human language used for the Formula Sheet explanations.
What happens next? When you run the Mentor Prompt with these two inputs, it generates a language-native MVCI Formula Sheet like the reference output shown below.
Formula Sheet of Atomic Structures
⚛️ Direct Pattern Matching
Theoretical Formula: Matching decomposes a structure and binds its components to variables.
# Define the input structure
data = {2, 4}
# Match and extract both values
{x, y} = data
result = x + y
IO.inspect(result) # Output: 6
⚛️ Exact case Branch
Theoretical Formula: case selects the first branch whose pattern matches the input.
# Define the input value
data = :a
# Match the value against exact patterns
result = case data do :a -> 1; :b -> 2 end
IO.inspect(result) # Output: 1
⚛️ Structural case Matching
Theoretical Formula: Structural patterns branch and extract values in one operation.
# Define the input structure
data = {:ok, 8}
# Match the structure and extract its value
result = case data do {:ok, x} -> x; {:error, _} -> 0 end
IO.inspect(result) # Output: 8
⚛️ Wildcard Fallback
Theoretical Formula: The wildcard pattern matches any value not handled by earlier branches.
# Define an unmatched input value
data = :c
# Use the wildcard as the fallback branch
result = case data do :a -> 1; :b -> 2; _ -> 0 end
IO.inspect(result) # Output: 0
⚛️ Pattern with Guard
Theoretical Formula: A guard adds a boolean constraint to an already matched pattern.
# Define the numeric input
data = 7
# Match the value and evaluate guard conditions
result = case data do x when x > 0 -> :positive; 0 -> :zero; _ -> :negative end
IO.inspect(result) # Output: :positive
⚛️ Pinned Pattern Value
Theoretical Formula: The pin operator matches against an existing value without rebinding it.
# Define the fixed value and input structure
x = 3
data = {3, 5}
# Require the first component to equal the existing value
result = case data do {^x, y} -> y; _ -> 0 end
IO.inspect(result) # Output: 5
⚛️ Map Pattern Matching
Theoretical Formula: Map patterns match required keys while ignoring unspecified entries.
# Define the input map
data = %{a: 2, b: 4}
# Match the required key and extract its value
result = case data do %{a: x} -> x; _ -> 0 end
IO.inspect(result) # Output: 2
⚛️ Ordered cond Branching
Theoretical Formula: cond selects the first condition that evaluates to a truthy value.
# Define the numeric input
data = 0
# Evaluate conditions sequentially
result = cond do data < 0 -> :negative; data == 0 -> :zero; data > 0 -> :positive end
IO.inspect(result) # Output: :zero
⚛️ cond Default Branch
Theoretical Formula: A final true condition provides an unconditional fallback branch.
# Define the input value
data = 8
# Evaluate conditions with a final fallback
result = cond do data < 0 -> :negative; rem(data, 2) == 1 -> :odd; true -> :other end
IO.inspect(result) # Output: :other
⚛️ Failed Pattern Match
Theoretical Formula: An unmatched direct assignment raises a MatchError instead of branching.
# Define an incompatible input structure
data = {2, 4}
# Attempt a nonmatching structural assignment
# {:ok, result} = data # Error: ** (MatchError) no match of right hand side value: {2, 4}
