Re: can format ~{...~} enumerate list items?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: can format ~{...~} enumerate list items?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 15. Aug 2024, 05:11:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9jrlk$qiqk$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
B. Pym wrote:

Pascal J. Bourguignon wrote:
 
(defun counting (list &optional (from 1))
  (mapcar (let ((i (1- from)))
            (lambda (x)
              (if (consp x)
                  (cons (incf i) x)
                  (list (incf i) x))))
          list))
 
(let ((arguments '(aa bb cc)))
  (format t "~:{~A. ~A~%~}"  (counting arguments)))
 
1. AA
2. BB
3. CC
 
Gauche Scheme
 
(define (print-counted the-list :optional (from 0))
  (for-each
    (lambda (i x) (print i ". " x))
    (lrange from)
    the-list))
 
gosh> (print-counted '(a bb ccc))
0. a
1. bb
2. ccc
 
gosh> (print-counted '(a bb ccc) 233)
233. a
234. bb
235. ccc
 
Shorter:
 
(define (print-counted the-list :optional (from 0))
  (for-each
    (cut print <> ". " <>)
    (lrange from)
    the-list))


newLISP

(define (print-counted the-list (from 0))
  (dolist (x the-list)
    (println (+ from $idx) ". " x)))

(print-counted '(aa bb cc) 700)
700. aa
701. bb
702. cc



Date Sujet#  Auteur
17 Jul 24 * Re: can format ~{...~} enumerate list items?3B. Pym
18 Jul 24 +- Re: can format ~{...~} enumerate list items?1Kaz Kylheku
15 Aug 24 `- Re: can format ~{...~} enumerate list items?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal