anistark / anistark/waspy

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

Aperta
#118 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
core-language enhancement good first issue priority-medium
Lingua principale
Rust
Stelle
22
Fork
6
Merge medio
1g 3h
PR unite (30g)
6

Descrizione

## 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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.