• Re: macros vs HOFs (was: O'Caml)

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Fri Aug 22 06:36:29 2025
    From Newsgroup: comp.lang.lisp

    Matthew Danish wrote:

    If you want to have some fun, why not write a nice higher-order function
    to do:

    (defun silly-loop (string &optional (increment 1) (final-char nil))
    (loop for n from 0 by increment
    for char across string
    until (eql char final-char)
    collect char into char-bag
    sum n into sum
    finally (return (values char-bag sum n))))

    Try to make it half as readable. And as efficient.

    Gauche

    (use gauche.sequence)

    (define (silly str :optional (inc 1) (ender #f))
    (do ((s str (subseq s 1))
    (n 0 (+ n inc))
    (bag '() (cons (~ s 0) bag))
    (sum 0 (+ n sum)))
    ((eq? ender (ref s 0 ender))
    (values (reverse bag) sum n))))

    (silly "catch" 37 #\h)

    (#\c #\a #\t #\c)
    222
    148
    --
    [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
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2