Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #21536
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Book titles |
| Date | 2013-04-09 04:06 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <kk043d$363$1@dont-email.me> (permalink) |
> > it to learn Lisp. Basically, for a list of book titles I wanted to
> > return a list of position in text and the book title, so
> > (build-book-index "wjhedbwjhbMarkajbdadbGenesis" *books*)
>
> > gave: ((21 "Genesis") (10 "Mark")).
>
> > 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)))
Factor:
USING: locals ascii sequences.extras ;
:: build-book-index ( books text -- seq )
text >upper :> utext
{ } books
[| book | book >upper utext start [ book 2array suffix ] when* ]
each
;
{ "Typee" "Mardi" "Pierre" "x" } "pierretypeemardi" build-book-index .
{ { 6 "Typee" } { 11 "Mardi" } { 0 "Pierre" } }
Back to comp.lang.forth | Previous | Next | Find similar
Book titles "WJ" <w_a_x_man@yahoo.com> - 2013-04-09 04:06 +0000
csiph-web