• Re: the "loop" macro

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Jun 18 13:50:25 2025
    From Newsgroup: comp.lang.lisp

    (loop for item in list
    maximize (f item))

    It's shorter in Gauche Scheme.

    (use srfi-42) ;; max-ec

    (max-ec (: x '(-8 2 0)) (abs x))
    ===>
    8
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Jun 18 13:55:08 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    (loop for item in list
    maximize (f item))

    It's shorter in Gauche Scheme.

    (use srfi-42) ;; max-ec

    (max-ec (: x '(-8 2 0)) (abs x))
    ===>
    8

    (loop for x in '(1 2 3 4 5 6 7)
    when (evenp x)
    collect x into evens
    else
    collect x into odds
    finally
    (return (values evens odds)))
    (2 4 6), (1 3 5 7)

    It's shorter in Gauche Scheme.

    (partition even? '(2 3 4 5 6 7))
    ===>
    (2 4 6)
    (3 5 7)

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Jun 18 14:00:51 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    B. Pym wrote:

    (loop for item in list
    maximize (f item))

    It's shorter in Gauche Scheme.

    (use srfi-42) ;; max-ec

    (max-ec (: x '(-8 2 0)) (abs x))
    ===>
    8

    (loop for x in '(1 2 3 4 5 6 7)
    when (evenp x)
    collect x into evens
    else
    collect x into odds
    finally
    (return (values evens odds)))
    (2 4 6), (1 3 5 7)

    It's shorter in Gauche Scheme.

    (partition even? '(2 3 4 5 6 7))
    ===>
    (2 4 6)
    (3 5 7)



    (loop for x in '(a b (c d) e f)
    when (atom x)
    collect x
    else
    append x)
    (A B C D E F)

    It's shorter in Gauche Scheme.

    (append-map
    (lambda (x) (if (pair? x) x (list x)))
    '(a b (c d) e f))
    ===>
    (a b c d e f)
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Jun 23 08:45:00 2025
    From Newsgroup: comp.lang.lisp

    M. Pitman wrote:

    (loop with best-foo = nil ;untested
    for foo in (list foo1 foo2)
    when (or (not best-foo)
    (> (weight foo) (weight best-foo)))
    do (setq best-foo foo)
    finally (return best-foo))

    Gauche Scheme:

    (use gauche.collection :only (find-max))

    (find-max '((a 2) (b 8) (c 5)) :key last)

    (b 8)
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Jun 30 03:22:58 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    B. Pym wrote:

    B. Pym wrote:

    (loop for item in list
    maximize (f item))

    It's shorter in Gauche Scheme.

    (use srfi-42) ;; max-ec

    (max-ec (: x '(-8 2 0)) (abs x))
    ===>
    8

    (loop for x in '(1 2 3 4 5 6 7)
    when (evenp x)
    collect x into evens
    else
    collect x into odds
    finally
    (return (values evens odds)))
    (2 4 6), (1 3 5 7)

    It's shorter in Gauche Scheme.

    (partition even? '(2 3 4 5 6 7))
    ===>
    (2 4 6)
    (3 5 7)

    Using collectors.

    (let ((odds (mlistbag)) (evens (mlistbag)))
    (dolist (x '(1 2 3 4 5 6 7))
    (if (odd? x) (odds x) (evens x)))
    (values (evens) (odds)))

    ===>
    (2 4 6)
    (1 3 5 7)


    Given:

    (define (mbag init func :optional (pass-through #f))
    (let ((val init) (func func) (pass-through pass-through))
    (lambda args
    (if (null? args)
    val
    (begin
    (set! val
    ;; A "kons" may have been supplied.
    ((if (null? (cdr args)) func (cadr args))
    (car args) val))
    (if pass-through
    (car args)
    val))))))
    (define (mlistbag :optional (pass-through #t))
    (let ((bag (mbag '() cons pass-through)))
    (lambda args
    (if (null? args)
    (reverse (bag))
    (apply bag args)))))
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Jun 30 17:27:35 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    M. Pitman wrote:

    (loop with best-foo = nil ;untested
    for foo in (list foo1 foo2)
    when (or (not best-foo)
    (> (weight foo) (weight best-foo)))
    do (setq best-foo foo)
    finally (return best-foo))

    Gauche Scheme:

    (use gauche.collection :only (find-max))

    (find-max '((a 2) (b 8) (c 5)) :key last)

    (b 8)

    (use gauche.sequence) ;; size-of

    (reduce
    (lambda(word best)
    (if (> (size-of word) (size-of best)) word best))
    #f ;; Returned if list is empty.
    '("a" "jut" "by" "cling" "saw"))

    ===>
    "cling"
    --- Synchronet 3.21d-Linux NewsLink 1.2