[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp version of CL: (format t "~:d" NUM)
From: |
Emanuel Berg |
Subject: |
Re: Elisp version of CL: (format t "~:d" NUM) |
Date: |
Fri, 21 May 2021 21:44:08 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Jean Louis wrote:
> In Common Lisp it is very easy to get readable comma
> separated digits:
https://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00369.html
> (defun number-comma-char (num)
> "For NUM return readable comma separated digits."
> (let* ((num (cond ((numberp num) (number-to-string num))
> (t num)))
> (decimal (string-match "\\." num))
> (rest (if decimal (substring num decimal) ""))
> (num (if decimal (substring num 0 decimal) num))
> (count 1)
> (list)
> (chain (seq-map 'identity (reverse num))))
> (while chain
> (let ((char (pop chain)))
> (cond ((and (= (truncate (/ count 3.0)) (/ count 3.0))
> chain)
> (progn
> (push char list)
> (push ?, list)))
> (t (push char list)))
> (setq count (1+ count))))
> (concat (mapconcat 'char-to-string list "") rest)))
Haha you are always so much fun with this semi-manual style of
yours :)
But good work...
--
underground experts united
https://dataswamp.org/~incal