William James
2/3/2016 8:51:00 PM
WJ wrote:
> Nils Goesche wrote:
>
> > > ok, lets say that we impliment that into a function like this:
> > >
> > > (defun find-position (word list)
> > > (let ((pos (position word list :key #'car)))
> > > (and pos (1+ pos))))
> > >
> > > and we modify our list:
> > >
> > > (setf my-list
> > > '((titi tata) (toto) (titi) (toto) (tada)))
> > >
> > > to contain several '(toto)s it will still return only the position of
> > > the first one
> > > 2
> > > whereas it should give us
> > > 2 4
> >
> > Ok, how about
> >
> > (defun find-position (word list)
> > (loop for sub in list
> > for index from 1
> > when (eq word (car sub))
> > collect index))
MatzLisp (Ruby):
def find_positions word, array
array.each_with_index.select{|(s),i| s==word}.map &:last
end
find_positions :toto, [[:titi,:tata],[:toto],[:titi],[:toto],[:tada]]
===>
[1, 3]
--
Blacks are an estimated 39 times more likely to commit a violent crime
against a white than vice versa, and 136 times more likely to commit robbery.
www.colorofcrime.com/2005/10/the-color-of-crime-2005/