Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #54218 > unrolled thread

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

Started by"Robert L." <No_spamming@noWhere_7073.org>
First post2017-01-21 07:52 +0000
Last post2017-01-21 07:52 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.forth


Contents

  .Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS? "Robert L." <No_spamming@noWhere_7073.org> - 2017-01-21 07:52 +0000

#54218 — .Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?

From"Robert L." <No_spamming@noWhere_7073.org>
Date2017-01-21 07:52 +0000
Subject.Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
Message-ID<o5v40m$1kbd$1@gioia.aioe.org>
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))

Ruby:

def find_indices array
  array.each_with_index.grep(->((n,i)){yield n}, &:last)
end

find_indices(%w(a bb c d e ff)){|s| s.size > 1}
    ==>[1, 5]

In Forth?


-- 
If confirmed, Garland would be the fourth Jewish justice on the nation's
highest court....  The three current Jewish members of the Supreme Court are
Ruth Bader Ginsburg, Elana Kagan, and Stephen Breyer.
www.jta.org/2016/03/16/news-opinion/united-states/obama-to-name-jewish-federal-judge-to-supreme-court

[toc] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web