Sujet : Re: Draconian function
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 06. Jul 2025, 16:12:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104e3pc$28tkg$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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