[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: YANQ - When to map, when to iterate, when to recurse?

William James

10/2/2015 9:55:00 PM

Wade Humeniuk wrote:

> (defun find-indices (list test)
> (loop for element in list
> for index from 1
> when (funcall test element) collect index))

Gauche Scheme:

(use srfi-42 :only (list-ec))

(define (get-indices xs test)
(list-ec (: x (index i) xs) (if (test x)) i))

gosh> (get-indices (iota 22) even?)
(0 2 4 6 8 10 12 14 16 18 20)
gosh> (get-indices (vector 3 4 5 6) even?)
(1 3)


Another way:

(define (get-indices xs test)
(filter-map
(lambda (x i) (and (test x) i))
xs
(lrange 1)))

gosh> (get-indices (iota 22) even?)
(1 3 5 7 9 11 13 15 17 19 21)

--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot
7 Answers

Bill M

6/20/2011 3:03:00 PM

0

You quite obviouslly have and over active and false imagination. Get a real
education - not
something taught by priests and nuns.

"duke" <duckgumbo32@cox.net> wrote in message
news:b91su612ctgfesj8rfpt2hiatstv3du6qc@4ax.com...
> On Mon, 6 Jun 2011 09:56:07 -0700 (PDT), grouch <ajo8272@gmail.com> wrote:
>
>>> Yet that is exactly the opposite of the truth. NOTHING is done with
>>> God's
>>> approval. God created man is his own image, and to do that, he had to
>>> give man
>>> a free will. Our free will allows us to follow God or to play God
>>> ourselves.
>>> This is the case reflected in the Adam & Eve story. God said "do not",
>>> and Eve
>>> said "we'll decide, not you". And so it began.
>>
>>Tell me about the free will of the people in the first book of the
>>Bible, ...following are 10 examples out of hundreds:
>
>>Genesis
>
>>Because God liked Abel's animal sacrifice more than Cain's vegetables,
>>Cain kills his brother Abel in a fit of religious jealousy. 4:8
>>
>>"I will destroy ... both man and beast."
>>God is angry. He decides to destroy all humans, beasts, creeping
>>things, fowls, and "all flesh wherein there is breath of life." He
>>plans to drown them all. 6:7, 17
>>
>>"Every living substance that I have made will I destroy."
>>God repeats his intention to kill "every living substance ... from off
>>the face of the earth." But why does God kill all the innocent
>>animals? What had they done to deserve his wrath? It seems God never
>>gets his fill of tormenting animals. 7:4
>>
>>"All flesh died that moved upon the earth."
>>God drowns everything that breathes air. From newborn babies to koala
>>bears -- all creatures great and small, the Lord God drowned them all.
>>7:21-23
>>
>>God sends a plague on the Pharaoh and his household because the
>>Pharaoh believed Abram's lie. 12:17
>>
>>God tells Abram to kill some animals for him. The needless slaughter
>>makes God feel better. 15:9-10
>>
>>Hagar conceives, making Sarai jealous. Abram tells Sarai to do to
>>Hagar whatever she wants. "And when Sarai dealt hardly with her, she
>>fled." 16:6
>>
>>"I will not destroy it for ten's sake."
>>I guess God couldn't find even ten good Sodomites because he decides
>>to kill them all in Genesis 19. Too bad Abraham didn't ask God about
>>the children. Why not save them? If Abraham could find 10 good
>>children, toddlers, infants, or babies, would God spare the city?
>>Apparently not. God doesn't give a damn about children. 18:32
>>
>>Lot refuses to give up his angels to the perverted mob, offering his
>>two "virgin daughters" instead. He tells the bunch of angel rapers to
>>"do unto them [his daughters] as is good in your eyes." This is the
>>same man that is called "just" and "righteous" in 2 Peter 2:7-8.
>>19:7-8
>>
>>God kills everyone (men, women, children, infants, newborns) in Sodom
>>and Gomorrah by raining "fire and brimstone from the Lord out of
>>heaven." Well, almost everyone -- he spares the "just and righteous"
>>Lot and his family. 19:24
>
> 1. Genesis 1-11 is not a scientific accounting of God's creation of the
> heavens
> and earth and all in it, but instead Israel's faith statement thereof.
> Gen
> 1-11 was written after 2 Kings.
>
> 2. God revealed to man, but man never met God. Moses "talked to a
> burning
> bush". Man has never seen God. But God became man in the person of
> Jesus
> Christ to die on the cross for the redemption from sin and the salvation
> of our
> souls.
>
> 3. Men thought they could call God their own, but not the God of their
> enemy.
> So they spoke and thought as though "their" God thought as they did. It's
> generally believed that the golden calf was not an item of worship but
> "something so beautiful" that God would move in and be theirs.
>
>>> And so we advise God in our personal lives as to our choice - him or us.
>>> And if
>>> we show we don't want any part of him in our lives now, he will grant us
>>> our
>>> chosen desire for all eternity.
>>
>>How do you advise an unknown, unseen, unheard, untouchable,
>>unreachable, untruthful God?
>
> We "advise" him by our human ways and selections: good over bad, right
> over
> wrong, love over hate.
>
> John 13:34 (New International Version)
> 34 "A new command I give you: Love one another. As I have loved you, so
> you
> must love one another.
>
> The dukester, American-American
> *****
> "The Mass is the most perfect form of Prayer."
> Pope Paul VI
> *****


Patrick

6/20/2011 4:18:00 PM

0

"Bill M" <wmech_1@netzero.net> wrote in message
news:EiJLp.10539$xh5.8951@newsfe02.iad...
> You quite obviouslly have and over active and false imagination. Get a
> real education - not something taught by priests and nuns.

Why do you say this?


duke

6/20/2011 6:39:00 PM

0

On Mon, 20 Jun 2011 11:02:47 -0400, "Bill M" <wmech_1@netzero.net> wrote:

>You quite obviouslly have and over active and false imagination. Get a real
>education - not
>something taught by priests and nuns.

That's superior to anything else.

The dukester, American-American
*****
"The Mass is the most perfect form of Prayer."
Pope Paul VI
*****

Kaz Kylheku

10/2/2015 10:32:00 PM

0

On 2015-10-02, WJ <w_a_x_man@yahoo.com> wrote:
> Wade Humeniuk wrote:
>
>> (defun find-indices (list test)
>> (loop for element in list
>> for index from 1
>> when (funcall test element) collect index))
>
> Gauche Scheme:
>
> (use srfi-42 :only (list-ec))
>
> (define (get-indices xs test)
> (list-ec (: x (index i) xs) (if (test x)) i))

> gosh> (get-indices (iota 22) even?)
> (0 2 4 6 8 10 12 14 16 18 20)
> gosh> (get-indices (vector 3 4 5 6) even?)
> (1 3)

TXR Lisp:

$ txr -i
1> [where evenp (range 0 22)]
(0 2 4 6 8 10 12 14 16 18 20 22)
2> [where evenp #(3 4 5 6)]
(1 3)
3> (let ((v (vec 3 4 5 6)))
(set [v [where evenp v]] '(a b c d))
v)
#(3 a 5 b)

William James

10/13/2015 4:55:00 AM

0

WJ wrote:

> Wade Humeniuk wrote:
>
> > (defun find-indices (list test)
> > (loop for element in list
> > for index from 1
> > when (funcall test element) collect index))

Portable Standard Lisp:

(load useful)

(de find-indices (list test)
(for (in element list)
(for index 1 (add1 index))
(when (funcall test element))
(collect index)))

(find-indices '(0 2 -3 -4) #'minusp)
===>
(3 4)

William James

10/13/2015 5:33:00 AM

0

WJ wrote:

> WJ wrote:
>
> > Wade Humeniuk wrote:
> >
> > > (defun find-indices (list test)
> > > (loop for element in list
> > > for index from 1
> > > when (funcall test element) collect index))
>
> Portable Standard Lisp:
>
> (load useful)
>
> (de find-indices (list test)
> (for (in element list)
> (for index 1 (add1 index))
> (when (funcall test element))
> (collect index)))
>
> (find-indices '(0 2 -3 -4) #'minusp)
> ===>
> (3 4)

Better:

(de find-indices (list test)
(for (in element list)
(from index 1)
(when (funcall test element))
(collect index)))

William James

10/29/2015 4:44:00 PM

0

WJ wrote:

> Wade Humeniuk wrote:
>
> > (defun find-indices (list test)
> > (loop for element in list
> > for index from 1
> > when (funcall test element) collect index))

MatzLisp (Ruby):

def get_indices xs
xs.each_with_index.flat_map{|x,i| yield(x) ? [i] : []}
end

get_indices(22..29){|n| n.odd?}
==>[1, 3, 5, 7]

--
Whereas Black-on-White crime motivated by racial hatred is vastly more common
than the reverse, such events are rarely reported in the national media, and
even local media typically ignore racial designations and downplay racial
motivation in such attacks. --- Dr. Kevin MacDonald