• re: Packages

    From B. Pym@21:1/5 to Kent M. Pitman on Sun Aug 10 07:59:51 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Mon Aug 11 23:44:11 2025
    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

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