anistark / anistark/waspy

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

Ouverte
#118 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
core-language enhancement good first issue priority-medium
Langage dominant
Rust
Étoiles
22
Forks
6
Merge moyen
1 j 3 h
PR mergées (30 j)
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

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python, rust, wasm
Domaine
compilers
Type d'issue
Fonctionnalité
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Active
Clarté
Clairement spécifiée
Accessibilité débutants
78/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.