From: Adi Aviad
Subject: (Newbie Q:) How to use stable-sort with a computed "key" field
Date: 
Message-ID: <f2e5ff95.0402110911.3d47a2e9@posting.google.com>
Hello,

I'm new in this, so it might be trivial but..
I try to use stable-sort to sort a list of lists. The folowing works fine:
         stable-sort (rest lol) #'> :key  #'second 
but I need the sorting by the ABSOLUTE value of the key field.

Any ideas ?

Thanks,
Adi

From: Joe Marshall
Subject: Re: (Newbie Q:) How to use stable-sort with a computed "key" field
Date: 
Message-ID: <8yj9h6dm.fsf@ccs.neu.edu>
·····@netvision.net.il (Adi Aviad) writes:

> Hello,
>
> I'm new in this, so it might be trivial but..
> I try to use stable-sort to sort a list of lists. The folowing works fine:
>          stable-sort (rest lol) #'> :key  #'second 
> but I need the sorting by the ABSOLUTE value of the key field.

:key (lambda (object) (abs (second object)))
From: Barry Margolin
Subject: Re: (Newbie Q:) How to use stable-sort with a computed "key" field
Date: 
Message-ID: <barmar-E036A4.12352911022004@comcast.ash.giganews.com>
In article <····························@posting.google.com>,
 ·····@netvision.net.il (Adi Aviad) wrote:

> Hello,
> 
> I'm new in this, so it might be trivial but..
> I try to use stable-sort to sort a list of lists. The folowing works fine:
>          stable-sort (rest lol) #'> :key  #'second 
> but I need the sorting by the ABSOLUTE value of the key field.
> 
> Any ideas ?

Change the :KEY parameter to a function that returns the absolute value 
of the key field.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Thomas F. Burdick
Subject: Re: (Newbie Q:) How to use stable-sort with a computed "key" field
Date: 
Message-ID: <xcvy8r96ucr.fsf@famine.OCF.Berkeley.EDU>
·····@netvision.net.il (Adi Aviad) writes:

> Hello,
> 
> I'm new in this, so it might be trivial but..
> I try to use stable-sort to sort a list of lists. The folowing works fine:
>          stable-sort (rest lol) #'> :key  #'second 
> but I need the sorting by the ABSOLUTE value of the key field.
> 
> Any ideas ?

(stable-sort (rest lol) #'> :key (compose #'abs #'second))

You'll need to write compose, of course, but it's a handy thing to
have around, once it's written.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Marco Antoniotti
Subject: Re: (Newbie Q:) How to use stable-sort with a computed "key" field
Date: 
Message-ID: <PuRWb.20$IJ5.2448@typhoon.nyu.edu>
Thomas F. Burdick wrote:
> ·····@netvision.net.il (Adi Aviad) writes:
> 
> 
>>Hello,
>>
>>I'm new in this, so it might be trivial but..
>>I try to use stable-sort to sort a list of lists. The folowing works fine:
>>         stable-sort (rest lol) #'> :key  #'second 
>>but I need the sorting by the ABSOLUTE value of the key field.
>>
>>Any ideas ?
> 
> 
> (stable-sort (rest lol) #'> :key (compose #'abs #'second))
> 
> You'll need to write compose, of course, but it's a handy thing to
> have around, once it's written.
> 

Veeery nice!

Cheers
--
marco.
From: Michael Livshin
Subject: Re: (Newbie Q:) How to use stable-sort with a computed "key" field
Date: 
Message-ID: <s3znbp4jh8.fsf@cmm.kakpryg.net.cmm>
·····@netvision.net.il (Adi Aviad) writes:

> I try to use stable-sort to sort a list of lists. The folowing works fine:
>          stable-sort (rest lol) #'> :key  #'second 
> but I need the sorting by the ABSOLUTE value of the key field.

if you read the documentation of `stable-sort', you'll see that the
second argument is called "predicate", and is required to be a
function that takes two arguments and returns a "generalized boolean".
the predicate in your example is #'>.

since your question seems to be about school homework, I'll stop
here.

-- 
All ITS machines now have hardware for a new machine instruction --
SETS
Set to Self.
Please update your programs.