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

    From B. Pym@21:1/5 to Pascal J. Bourguignon on Wed Jul 17 21:20:33 2024
    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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Thu Jul 18 00:38:05 2024
    On 2024-07-17, B. Pym <Nobody447095@here-nor-there.org> wrote:
    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))

    This is the TXR Lisp interactive listener of TXR 294.
    Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
    TXR was taped live before a studio audience. The laughter is genuine.
    (mapdo (op put-line `@1. @2`) 1 '(a bb ccc))
    1. a
    2. bb
    3. ccc

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Thu Aug 15 03:11:50 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)