From: Lieven Marchand
Subject: Re: newbie Q: insertion into sorted list
Date: 
Message-ID: <m3pufhk57o.fsf@localhost.localdomain>
"James Goodzeit" <········@email.msn.com> writes:

> Hello
> 
> Is there any Lisp primitives or nifty functions for inserting a key to the
> right place in a sorted list---using something like (sort (cons x l)) seems
> it will be extravagantly wasteful. 

(merge 'list sorted-list (list item) #'<) should be fairly efficient
for a reasonable implementation of merge.

> also what would how would i do something
> like
> 
> (position-if 4 '(1 3 5 7) :test #'<) ; bogus
> ==>2
> 
> in Allegro Common Lisp?
> 

(count-if #'(lambda(x) (< x 4)) '(1 3 5 7))

> TIA
> James
> 
> 

-- 
Lieven Marchand <···@wyrd.be>
Gla�r ok reifr skyli gumna hverr, unz sinn b��r bana.
From: Michael Kappert
Subject: Re: newbie Q: insertion into sorted list
Date: 
Message-ID: <3AB298D1.5656EA63@iitb.fhg.de>
Lieven Marchand wrote:
 
> "James Goodzeit" <········@email.msn.com> writes:

> > also what would how would i do something
> > like

> > (position-if 4 '(1 3 5 7) :test #'<) ; bogus
> > ==>2

> > in Allegro Common Lisp?

> (count-if #'(lambda(x) (< x 4)) '(1 3 5 7))

Why not just
  (position 4 '(1 3 5 7) :test #'<)
?

Michael
 
--