Deutsch   English   Français   Italiano  
<vcmjg5$1kcla$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
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=
Bytes: 1496

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)