Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How can I sort symbols in alphabetical order?

1,602 views
Skip to first unread message
Message has been deleted

Mattias Nilsson

unread,
Nov 29, 2005, 8:36:10 AM11/29/05
to
Kubilay wrote:
> How can I sort symbols in alpahbetical order?

Well, I'm just a beginner, but here's my attempt:

(sort '(car window apple) #'string< :key #'symbol-name)

Note that it both takes and returns a list of symbols.

Mattias.

Timofei Shatrov

unread,
Nov 29, 2005, 8:40:19 AM11/29/05
to
On 29 Nov 2005 04:08:54 -0800, "Kubilay" <kubil...@gmail.com> tried
to confuse everyone with this message:

>How can I sort symbols in alpahbetical order? I mean:
>
>(my-dear-function '(car) '(window) '(apple)) should return
>
>apple
>car
>window
>
>or something like that. Is there a built-in function?
>
>Thanks in advance.
>

A simple combination of three built-in functions will do the job.

(sort '(car window apple)
(lambda (x y) (string< (symbol-name x) (symbol-name y))))

--
|a\o/r|,-------------.,---------- Timofei Shatrov aka Grue ------------.
| m"a ||FC AMKAR PERM|| mail: grue at mail.ru http://grue3.tripod.com |
| k || PWNZ J00 || Kingdom of Loathing: Grue3 lvl 18 Seal Clubber |
`-----'`-------------'`-------------------------------------------[4*72]

Lars Brinkhoff

unread,
Nov 29, 2005, 8:53:11 AM11/29/05
to
"Mattias Nilsson" <matt...@bredband.net> writes:
> (sort '(car window apple) #'string< :key #'symbol-name)

gr...@mail.ru (Timofei Shatrov) writes:
> (sort '(car window apple)
> (lambda (x y) (string< (symbol-name x) (symbol-name y))))

Note that sort is advertised as a destructive function, and you pass
it a quoted object.

Mattias Nilsson

unread,
Nov 29, 2005, 9:17:00 AM11/29/05
to
Lars Brinkhoff wrote:
> "Mattias Nilsson" <matt...@bredband.net> writes:
> > (sort '(car window apple) #'string< :key #'symbol-name)
:

> Note that sort is advertised as a destructive function, and you pass
> it a quoted object.

Of course! I intended for my answer to be a template that could
be used in a destructive function. ;)

Zach Beane

unread,
Nov 29, 2005, 9:25:49 AM11/29/05
to
gr...@mail.ru (Timofei Shatrov) writes:

> On 29 Nov 2005 04:08:54 -0800, "Kubilay" <kubil...@gmail.com> tried
> to confuse everyone with this message:
>
> >How can I sort symbols in alpahbetical order? I mean:

[snip]


>
> A simple combination of three built-in functions will do the job.
>
> (sort '(car window apple)
> (lambda (x y) (string< (symbol-name x) (symbol-name y))))
>

STRING< takes string designators, and symbols are string designators.

(sort (list 'foo 'bar 'baz) #'string<) => (BAR BAZ FOO)

Zach

Message has been deleted

Edi Weitz

unread,
Nov 29, 2005, 10:08:00 AM11/29/05
to
On 29 Nov 2005 06:44:19 -0800, "Kubilay" <kubil...@gmail.com> wrote:

> Good Lord! Was it so simple? How did you know the "sort" function?
> Did you already somehow learned it or did you looked at a reference?

Oh, you don't know /the/ reference? Here it is:

<http://www.lispworks.com/documentation/HyperSpec/Front/index.htm>

Note (we just had this) that this is not a tutorial or something like
that - don't expect to be able to learn CL from this alone - see

<http://www.lispworks.com/documentation/HyperSpec/Body/01_aa.htm>

> What should I do in such situations? Should I think in plain English
> and after that use "apropos"?

That's a good first step.

Cheers,
Edi.

--

Lisp is not dead, it just smells funny.

Real email: (replace (subseq "spam...@agharta.de" 5) "edi")

Zach Beane

unread,
Nov 29, 2005, 10:25:39 AM11/29/05
to
"Kubilay" <kubil...@gmail.com> writes:

> Good Lord! Was it so simple? How did you know the "sort" function? Did

> you already somehow learned it or did you looked at a reference? What


> should I do in such situations? Should I think in plain English and
> after that use "apropos"?
>

> I cannot always find great people like you to ask ;-)

Although it's not completely accurate any more, I found it helpful to
read Common Lisp, the Language, 2nd Ed, from cover to cover. Even if
not everything sticks perfectly in your mind, the next time you run
into a problem you may think "Oh yeah, I remember something about
this..."

Zach

Bulent Murtezaoglu

unread,
Nov 29, 2005, 10:37:37 AM11/29/05
to
>>>>> "ZB" == Zach Beane <xa...@xach.com> writes:
[...]
ZB> Although it's not completely accurate any more, I found it
ZB> helpful to read Common Lisp, the Language, 2nd Ed, from cover
ZB> to cover. [...]

I'll second this. Reading random sections helps too. I have the physical
book, but printing and comb binding etc. would also work. It is downladable.
Here's the cliki link: http://www.cliki.net/CLtL2

cheers,

BM

0 new messages