alphapapa / alphapapa/prism.el

(prism-expand-list) is very broken

Offen
#4 3 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @alphapapa Auf GitHub ansehen
bug
Vorherrschende Sprache
Emacs Lisp
Sterne
334
Forks
5
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

For example:

`(prism-expand-list 4 '(1 2 3)) ;; => (1 1 2 2 3 3 3)`

The problem is in how `repeat-n` is determined. Here's my proposed solution, but I'm not sure if it's exactly what you want, because it repeats the last element potentially many times, while the documentation says it will be repeated only one time.

```lisp
(defun prism-expand-list (new-length list)
"Return LIST expanded to NEW-LENGTH.
Each element of LIST is repeated an equal number of times, except
that the last element may be repeated an extra time when
necessary."
(let* ((length (length list))
(_longer-p (or (> new-length length)
(user-error "NEW-LENGTH must be longer than LIST")))
(repeat-n (/ new-length length))
(final-element-repeat-n (mod new-length length))
(final-elements (and (< 0 final-element-repeat-n)
(-repeat final-element-repeat-n (-last-item list))))
(new-list (->> list
(--map (-repeat repeat-n it))
(-flatten))))
(if final-elements
(apply #'-snoc new-list final-elements)
new-list)))
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.