[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: qsort optimized for brevity

William James

9/26/2015 8:47:00 PM

> (defun partition (list &aux (pivot-value (first list)))
> (loop for item in list
> if (< item pivot-value)
> collect item into less
> else
> collect item into greater-or-equal
> finally (return (values less greater-or-equal))))
>
> Never underestimate the power of LOOP :)

Gauche Scheme:

gosh> (partition odd? '(2 0 9 4 3 6))
(9 3)
(2 0 4 6)

--
In Stockholm ... 20 Muslim men ... began to assault the children, ripping their
swimsuits off.... [T]he men cornered one of the [11-year-old] girls in a
grotto in the bathhouse and gang-raped her. The police refused to press any
charges. www.liveleak.com/view?i=807_1369627137
2 Answers

William James

10/13/2015 6:20:00 AM

0

WJ wrote:

> > (defun partition (list &aux (pivot-value (first list)))
> > (loop for item in list
> > if (< item pivot-value)
> > collect item into less
> > else
> > collect item into greater-or-equal
> > finally (return (values less greater-or-equal))))
> >

Portable Standard Lisp:

(load numeric-ops)

(de partition (list)
(let (less gte)
(foreach item in list do
(if (< item (car list))
(push item less)
(push item gte)))
(mapcar (list less gte) #'reverse)))

4 lisp> (partition '(5 4 7 8 0))
((4 0) (5 7 8))

William James

10/29/2015 9:04:00 AM

0

WJ wrote:

> > (defun partition (list &aux (pivot-value (first list)))
> > (loop for item in list
> > if (< item pivot-value)
> > collect item into less
> > else
> > collect item into greater-or-equal
> > finally (return (values less greater-or-equal))))
> >
> > Never underestimate the power of LOOP :)
>
> Gauche Scheme:
>
> gosh> (partition odd? '(2 0 9 4 3 6))
> (9 3)
> (2 0 4 6)

MatzLisp (Ruby):

[2,0,9,4,3,6].partition &:odd?
==>[[9, 3], [2, 0, 4, 6]]

--
Let us be brought to believe it is ... favorable to ... our interest to
transfer the African to his native clime, and we shall find a way to do it,
however great the task may be. --- A. Lincoln, Sept. 22, 1856