Groups | Search | Server Info | Login | Register
Groups > comp.lang.scheme > #6518
| From | "B. Pym" <Nobody447095@here-nor-there.org> |
|---|---|
| Newsgroups | comp.lang.lisp, comp.lang.scheme |
| Subject | Re: List of digits->number |
| Date | 2025-07-18 01:48 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <105c94l$1lmk2$1@dont-email.me> (permalink) |
| References | <vcmjg5$1kcla$1@dont-email.me> |
Cross-posted to 2 groups.
B. Pym wrote:
> 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)
(do ((n 1984 (div n 10))
(r () (cons (mod n 10) r)))
((zero? n) r))
===>
(1 9 8 4)
--
[T]he problem is that lispniks are as cultish as any other
devout group and basically fall down frothing at the mouth if
they see [heterodoxy]. --- Kenny Tilton (05 Dec 2004)
Back to comp.lang.scheme | Previous | Next — Previous in thread | Find similar
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