Skip to content

Add List-Ops practice exercise#161

Closed
jojo8356 wants to merge 4 commits intoexercism:mainfrom
jojo8356:add-list-ops-exercise
Closed

Add List-Ops practice exercise#161
jojo8356 wants to merge 4 commits intoexercism:mainfrom
jojo8356:add-list-ops-exercise

Conversation

@jojo8356
Copy link
Copy Markdown

Closes #158

Summary

  • Add list-ops practice exercise (difficulty 3)
  • 8 operations: append, concat, filter, length, map, foldl, foldr, reverse
  • Reference solution using pure recursion (no stdlib list functions)
  • Test generator with function string → Lean lambda mapping
  • 22 test cases from canonical data (integer division for fold tests)

Files

  • exercises/practice/list-ops/ — full exercise (stub, tests, example, docs, lakefile)
  • generators/Generator/Generator/ListOpsGenerator.lean — test generator
  • generators/Generator/Generator.lean — updated dispatch table
  • config.json — added exercise entry

Implements all 8 list operations: append, concat, filter, length,
map, foldl, foldr, reverse. Includes test generator, reference
solution, and 22 test cases from canonical data.

Closes #158
@github-actions
Copy link
Copy Markdown
Contributor

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

If you're interested in learning more about this auto-responder, please read this blog post.


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@github-actions github-actions bot closed this Mar 24, 2026
@keiravillekode
Copy link
Copy Markdown
Contributor

Next time, please follow How to contribute

@@ -0,0 +1,18 @@
{
"authors": [
"oxe-i"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be your github username

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I maj with claude because I am in another project with and I am tired, sorry.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maj = update

@oxe-i oxe-i added x:rep/medium Medium amount of reputation x:size/medium Medium amount of work labels Mar 24, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
config.json Outdated
"difficulty": 3
},
{
"slug": "list-ops",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exercises of the same difficulty are organized in alphabetical order. You should use bin/reorder-exercises

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, ran bin/reorder-exercises to fix the ordering. Thanks for the review!

| "foldr", "\"(acc, el) -> el + acc\"" => "(fun el acc => el + acc)"
| "foldr", "\"(x, y) -> x / y\"" => "(· / ·)"
| _, _ => funStr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could define another function ^ for integer power.

  | "foldl", "\"(acc, el) -> el ^ acc\"" => "(fun acc el => el ^ acc)"
  | "foldr", "\"(acc, el) -> el ^ acc\"" => "(fun el acc => el ^ acc)"

We could have a .meta/extra.json like the meetup or atbash-cipher or grep exercises, to compute 3 ^ (2 ^ 5) or 2 ^ (3 ^ 5) using foldl or foldr.

          "input": {
            "list": [2, 3],
            "initial": 5,
            "function": "(acc, el) -> el ^ acc"
          },

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added power (^) mappings to the generator and created .meta/extra.json with two extra test cases for foldl/foldr using el ^ acc on [3, 2] with initial 2 (foldl → 512, foldr → 81).
All 24 tests pass.

@keiravillekode
Copy link
Copy Markdown
Contributor

I don't think you ran the generator.

If we look at some extra.json files, we see they have an array at the top level. We can have

[
  {
    "description": "folds (reduces) the given list from the left with a function -> direction dependent function applied to non-empty list (power)",
    "property": "foldl",
    "input": {
      "list": [2, 5],
      "initial": 3,
      "function": "(acc, el) -> el ^ acc"
    },
    "expected": 390625
  },
  {
    "description": "folds (reduces) the given list from the right with a function -> direction dependent function applied to non-empty list (power)",
    "property": "foldr",
    "input": {
      "list": [5, 3],
      "initial": 2,
      "function": "(acc, el) -> el ^ acc"
    },
    "expected": 1953125
  }
]

The generator can have

  | "foldl", "\"(acc, el) -> el * acc\"" => "(fun acc el => acc * el)"
  | "foldl", "\"(acc, el) -> el + acc\"" => "(fun acc el => acc + el)"

and

  | "foldl", "\"(acc, el) -> el ^ acc\"" => "(fun acc (el : UInt8) => (UInt8.toNat el) ^ acc)"
  | "foldr", "\"(acc, el) -> el ^ acc\"" => "(fun (el : UInt8) acc => (UInt8.toNat el) ^ acc)"

You can run the generator using

cd generators
lake exe generator -g list-ops

@oxe-i
Copy link
Copy Markdown
Contributor

oxe-i commented Mar 25, 2026

@jojo8356 It seems you are not running the generator script, as you should, and so the test file does not necessarily match the generator file for the exercise.

Since this PR does not follow our contribution guidelines, it will be closed. Thank you for your contribution.

@oxe-i oxe-i closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

x:rep/medium Medium amount of reputation x:size/medium Medium amount of work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add List-Ops practice exercise

3 participants