Skip to content

Conversation

Copy link

Copilot AI commented Dec 9, 2025

Three areas of code duplication were eliminated through extraction to helper functions:

Changes

  • sexp.rs: Extracted wrap_tokens_with_special_chars() from two identical 23-line blocks that wrapped tokens with quote/backtick/comma patterns in expand_special_characters()

  • eval.rs: Extracted eval_statements_sequentially() from duplicate logic in Let and Progn that iterated statements and returned the last evaluation result

  • eval.rs: Extracted eval_binary_arithmetic_op() and eval_binary_comparison_op() from repetitive arithmetic (+, -, *, /, %) and comparison (<, >) operation handlers

Example

Before:

"-" => Rc::new(Sexp::Num(
    eval_sexp_to_num(l[1].clone(), state) - eval_sexp_to_num(l[2].clone(), state),
)),
"+" => Rc::new(Sexp::Num(
    eval_sexp_to_num(l[1].clone(), state) + eval_sexp_to_num(l[2].clone(), state),
)),

After:

"-" => eval_binary_arithmetic_op(l, state, |a, b| a - b),
"+" => eval_binary_arithmetic_op(l, state, |a, b| a + b),

Net reduction: 12 lines of code, with improved maintainability through reusable abstractions.

Original prompt

Find and refactor duplicated code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 9, 2025 17:01
Co-authored-by: Giedriusj1 <1835596+Giedriusj1@users.noreply.github.com>
Co-authored-by: Giedriusj1 <1835596+Giedriusj1@users.noreply.github.com>
Co-authored-by: Giedriusj1 <1835596+Giedriusj1@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor: Extract duplicated code patterns into reusable helpers Dec 9, 2025
Copilot AI requested a review from Giedriusj1 December 9, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants