• Re: Draconian function

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Sun Jul 6 15:12:45 2025
    From Newsgroup: comp.lang.scheme

    Which means you can use LOOP:

    (defun count-constraints-involvement (val list)
    (loop for row in *rows*
    when (and (find val row) (some (lambda (y) (find y row)) list)))
    sum 1))

    Or even:

    (loop for row in *rows*
    count (and (find val row)
    (some (lambda (y) (find y row)) list)))

    Gauche Scheme

    (use srfi-42) ;; sum-ec
    (use srfi-1) ;; lset-intersection

    (define *rows* '((77 0 2 3) (88 0 2 3) (88 5 6) (88 7 8 9)))

    (define (count-constraints-involvement one-val many-vals)
    (sum-ec (:list row *rows*)
    (if (member one-val row))
    (if (pair? (lset-intersection equal? many-vals row)))
    1))

    (count-constraints-involvement 77 '(0 8))
    ===>
    1

    (count-constraints-involvement 88 '(0 8))
    ===>
    2

    (count-constraints-involvement 88 '(5 6))
    ===>
    1

    (count-constraints-involvement 99 '(5 6))
    ===>
    0
    --- Synchronet 3.21a-Linux NewsLink 1.2