Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #411: Traffic jam on the Information Superhighway.


comp / comp.lang.lisp / Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?

SubjectAuthor
o Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?B. Pym

1
Subject: Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 5 Jul 2024 22:36 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
Date: Fri, 5 Jul 2024 22:36:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <v69sgh$3ffop$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 06 Jul 2024 00:36:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="36dabbcb546c8dd3a3c5c81a41ee2e18";
logging-data="3653401"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WvU1F00gm0op+FWskJXaU"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:NyVTNlHt5hVXlozE5XaLw8eJx7k=
View all headers

Wade Humeniuk wrote:

> John Connors wrote:
>
> > Yet Another Noob Question.
>
> > What are the characteristics of each implementation?
>
> > How can I tell which I should be writing in what context...
>
> > (defun find-indicies (lst tst)
> > (let ((li 0))
> > (labels ((qpred (a)
> > (incf li)
> > (if (funcall tst a)
> > (1- li)
> > nil)))
> > (remove nil (mapcar #'qpred lst)))))
>
> > (defun find-indices (lst tst)
> > (loop
> > for el in lst
> > counting t into index
> > if (funcall tst el)
> > collect index))
>
> You are allergic to loop
>
> (defun find-indices (list test)
> (loop for element in list
> for index from 1
> when (funcall test element) collect index))

Gauche Scheme

(define (find-indices lst test)
(filter-map
(lambda (e i) (and (test e) i))
lst
(lrange 1)))

(find-indices '(0 88 409 66 77) odd?)
===>
(3 5)

1

rocksolid light 0.9.8
clearnet tor