Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.lisp > #60170

Re: List of digits->number

From "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups comp.lang.lisp, comp.lang.scheme
Subject Re: List of digits->number
Date 2024-09-21 13:59 +0000
Organization A noiseless patient Spider
Message-ID <vcmjg5$1kcla$1@dont-email.me> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


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)

Back to comp.lang.lisp | Previous | NextNext in thread | Find similar


Thread

Re: List of digits->number "B. Pym" <Nobody447095@here-nor-there.org> - 2024-09-21 13:59 +0000
  Re: List of digits->number "B. Pym" <Nobody447095@here-nor-there.org> - 2025-07-18 01:48 +0000

csiph-web