Sujet : Re: List of digits->number
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 21. Sep 2024, 14:59:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vcmjg5$1kcla$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Frank Buss wrote:
(defun split-backward (number &optional (base 10))
(loop while (< 0 number) collect
(multiple-value-bind (quotient remainder) (floor number base)
(setf number quotient)
remainder)))
LOOP is ok, but I wonder if there is a more elegant contruct like REDUCE
for the opposite concept for building a list. Building the list should not
need more program code characters than reducing the list.
Testing:
* (split-backward 1984)
(4 8 9 1)
Gauche Scheme
(use srfi-1) ; unfold
(unfold zero? (cut mod <> 10) (cut quotient <> 10) 1984)
===>
(4 8 9 1)