• re: Packages

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Sun Aug 10 07:59:51 2025
    From Newsgroup: comp.lang.lisp

    Kent M. Pitman wrote:

    (defun find-longest-name (array-of-symbols)
    (let ((longest (aref array-of-symbols 0))) ;!!! assumes at least one elt
    (loop for i from 1 below (length array-of-symbols)
    for contender = (aref array-of-symbols i)
    when (> (length (string longest))
    (length (string contender)))
    do (setf longest contender))
    longest))

    Gauche Scheme

    (use gauche.sequence)

    (define (find-longest-name vec-of-symbols)
    (do ((names (map x->string vec-of-symbols))
    (longest ""))
    ((null? names) longest)
    (set! longest
    (car (sort (list longest (pop! names)) > size-of)))))

    (find-longest-name #(one two three four))
    ===>
    "three"
    --
    [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
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Aug 11 23:44:11 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    Kent M. Pitman wrote:

    (defun find-longest-name (array-of-symbols)
    (let ((longest (aref array-of-symbols 0))) ;!!! assumes at least one elt
    (loop for i from 1 below (length array-of-symbols)
    for contender = (aref array-of-symbols i)
    when (> (length (string longest))
    (length (string contender)))
    do (setf longest contender))
    longest))

    Gauche Scheme

    (use gauche.sequence)

    (define (find-longest-name vec-of-symbols)
    (do ((names (map x->string vec-of-symbols))
    (longest ""))
    ((null? names) longest)
    (set! longest
    (car (sort (list longest (pop! names)) > size-of)))))

    (find-longest-name #(one two three four))
    ===>
    "three"

    (define (find-longest-name vec-of-symbols)
    (let1 names (map x->string (vector->list vec-of-symbols))
    (max-by string-length names)))

    Given:

    (define (max-by func xs)
    (if (null? xs)
    #f
    (let ((best (pop! xs)))
    (if (null? xs)
    best
    (do ((best-val (func best)))
    ((null? xs) best)
    (let* ((this (pop! xs))
    (this-val (func this)))
    (when (> this-val best-val)
    (set! best this)
    (set! best-val this-val))))))))
    --
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2