Re: Lost in Loop

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Lost in Loop
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 18. Jun 2025, 11:56:39
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102u613$3364k$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Pascal Bourguignon wrote:

I had an approach working but it looked horrid so I thought I would try
loop.  I came up with this:
>
(defun build-book-index (text books)
 (loop for book in books
    when (search (string-downcase book) (string-downcase text)) collect
    (list it book)))
>
Of course, ...collect it ... worked but the version above gave:
>
in: LAMBDA NIL
;     (LIST IT BOOK)
; caught WARNING:  undefined variable: IT
>
Is this expected?
 
Yes.
 
How can I get round it?
 
Not using IT.
 
(defun build-book-index (text books)
  (loop
     for book in books
     for my-it = (search (string-downcase book) (string-downcase text))
     when my-it collect (list my-it book)))

It's shorter in Gauche Scheme.

(use srfi-13)  ;; string-contains

(define (build-book-index text books)
  (filter-map
    (lambda (book)
      (let1 p (string-contains-ci text book)
        (and p (list p book))))
    books))

(build-book-index "a foo or a bar" '("FOO" "bar" "zoom"))

  ===>
((2 "FOO") (11 "bar"))

Date Sujet#  Auteur
18 Jun 25 o Re: Lost in Loop1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal