anistark / anistark/waspy

enhancement: support min() and max() over a single iterable

Open
#118 0 comments 0 reactions 0 assignees View on GitHub
core-language enhancement good first issue priority-medium
Dominant language
Rust
Stars
22
Forks
6
Avg merge
1d 3h
Merged PRs (30d)
6

Description

## Summary

`min()` and `max()` work over several arguments (`min(a, b, c)`) but not over a single iterable (`min(xs)`), which is the more common form. It is rejected at validation time with a hint, so nothing miscompiles; the feature is simply missing.

## Current state

- The multi-argument form folds the arguments into a running minimum: https://github.com/anistark/waspy/blob/d7dcbc4/src/compiler/expression.rs#L4668-L4690
- The single-iterable form is refused during validation with `min() over a single iterable argument is not supported`.

```python
def m() -> int:
xs = [3, 1, 2]
return min(xs) # rejected today; CPython answers 1
```

## Proposed change

Walk the collection and fold, the way `sum()` already does. `sum()` was implemented in 0.14.0 over the same `[len][cap][slot...]` layout and is a direct model, including reading each element at its natural width so a float list compares as f64 rather than as its low word.

Both `min` and `max` are the same loop with the comparison flipped.

## Acceptance criteria

- [ ] `min(xs)` and `max(xs)` over a list or tuple of ints answer what CPython answers
- [ ] The same over a list of floats, compared at f64 width
- [ ] An empty iterable fails loudly (CPython raises `ValueError`)
- [ ] The existing multi-argument form still works
- [ ] Asserted tests, comparing against CPython's answers for the same source

## References

- `sum()` over a list, the model to copy: https://github.com/anistark/waspy/blob/d7dcbc4/src/compiler/expression.rs#L4434

Contributor guide

Open the contributing guide

Research direction

Start in src/compiler/expression.rs at the existing multi-argument min/max handling around lines 4668-4690, then read the sum() list implementation around line 4434 and the validation message for single iterable arguments. Add asserted tests for integer and float lists or tuples, empty iterables, and the existing multi-argument form, comparing results with CPython; done means all acceptance criteria pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust, wasm
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.