Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Make a wish, it might come true.


comp / comp.lang.scheme / Re: List of digits->number

SubjectAuthor
o Re: List of digits->numberB. Pym

1
Subject: Re: List of digits->number
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 21 Sep 2024 13:59 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: List of digits->number
Date: Sat, 21 Sep 2024 13:59:34 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <vcmjg5$1kcla$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 21 Sep 2024 15:59:34 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="75bf4db5387dcb76189623713453f22d";
logging-data="1716906"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pRVRmBhczyTgf6+Bw+Riy"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:vpVcOa9tDsj7uIjFT5OQehZQ/jk=
View all headers

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)

1

rocksolid light 0.9.8
clearnet tor