From: THaawk
Subject: beginner help - string processing
Date: 
Message-ID: <88394q$25j$1@news7.svr.pol.co.uk>
I am trying to write a function (str_proc) that can accept a string ie:

(str_proc '(hello out there))

It will then return them alphabetically and in size order, ie.

hello                |
out                  |  -  alphabetically
there               |
out         |
hello       |  -  size order
there      |

if there were two words the same size, then it should count them, ie.

(str_proc '(hello out there you))

hello
out
there
you
out - appears once
you - appears once
hello
there

Thank you

From: Robert Monfera
Subject: Re: beginner help - string processing
Date: 
Message-ID: <38A62BBF.744DAFAA@fisec.com>
THaawk wrote:
>
> I am trying to write a function

I thought you just want to avoid homework.

> (str_proc)

Don't use _ in Lisp, and name your function based on what it does
(verb), rather than "processing" or some other meaningless name.  If you
don't want to name it, you can define anonymous functions.

> that can accept a string ie:
>
> (str_proc '(hello out there))

(hello out there) is not a string, but a list.

> It will then return them alphabetically and in size order, ie.
>
> hello                |
> out                  |  -  alphabetically
> there               |
> out         |
> hello       |  -  size order
> there      |

This solution REDUCEs your homework efforts (if you are allowed to use
it, that is).

;;; Essential utilities
(defun compose (&rest functions)
    (flet ((reversed-funcall (single-argument function)
             (funcall function single-argument)))
      (lambda (&rest args)
        (reduce #'reversed-funcall (rest functions)
                :initial-value (apply (first functions) args)))))))

;;; Solution
(defun symbol-name-sort (symbol-list)
   (sort symbol-list #'string-lessp :key #'symbol-name))

(defun symbol-name-length-sort (symbol-list)
    (sort symbol-list #'< :key (compose #'symbol-name #'length)))

Now you just have to loop through the result and count identical
symbols, which should not be a big deal.

What's the purpose of this exercise?  Why do you attend a Lisp class if
you don't want to invest in your homework?  Did you ask help from your
teacher or your classmates?  How can you make sure your prof does not
read c.l.l.?

Robert
From: ·············@not.for.spam
Subject: Re: beginner help - string processing
Date: 
Message-ID: <38aa78bb.264850174@news.earthlink.net>
On Sat, 12 Feb 2000 22:57:51 -0500, Robert Monfera <·······@fisec.com> wrote:

>This solution REDUCEs your homework efforts (if you are allowed to use

Here's a solution in Smalltalk.  If he turns this in as his homework, it
will be educational:

Array>>quirkSort
   ^ (self asSortedCollection: [:a :b | a <= b]) asArray
   ,  (self asSortedCollection: [:a :b | a size <= b size]) asArray.

Example usage:
Input:         #(hello out there) quirkSort
Answer:    #(#hello #out #there #out #hello #there)
Input:         #('hello' 'out' 'there') quirkSort
Answer:    #('hello' 'out' 'there' 'out' 'hello' 'there')
From: Marco Antoniotti
Subject: Re: beginner help - string processing
Date: 
Message-ID: <lwr9eelo9b.fsf@parades.rm.cnr.it>
Robert Monfera <·······@fisec.com> writes:

> What's the purpose of this exercise?  Why do you attend a Lisp class if
> you don't want to invest in your homework?  Did you ask help from your
> teacher or your classmates?  How can you make sure your prof does not
> read c.l.l.?

The real problem is:

how do you make sure a teacher *does read* C.L.L. so that he won't
give out stupid exercises and bogus information? :) (BTW. I used the
masculine pronoun on purpose - men tend to be more block headed :) ).

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Tim Bradshaw
Subject: Re: beginner help - string processing
Date: 
Message-ID: <ey3itzqwv0j.fsf@cley.com>
* Marco Antoniotti wrote:

> how do you make sure a teacher *does read* C.L.L. so that he won't
> give out stupid exercises and bogus information? :) (BTW. I used the
> masculine pronoun on purpose - men tend to be more block headed :) ).

I'm curious -- does anyone who is reading this actually teach Lisp in
an academic context?  I get the strong impression that it's almost a
prerequisite of Lisp teaching in academia to be 30 years out of
date...

--tim
From: Robert STRANDH
Subject: Re: beginner help - string processing
Date: 
Message-ID: <6w7lg6jwbi.fsf@napperon.labri.u-bordeaux.fr>
Tim Bradshaw <···@cley.com> writes:

> I'm curious -- does anyone who is reading this actually teach Lisp in
> an academic context?

Yes, at least one. 

-- 
Robert Strandh

---------------------------------------------------------------------
Greenspun's Tenth Rule of Programming: any sufficiently complicated C
or Fortran program contains an ad hoc informally-specified bug-ridden
slow implementation of half of Common Lisp.
---------------------------------------------------------------------
From: William Deakin
Subject: Re: beginner help - string processing
Date: 
Message-ID: <38A95BEB.B6618ABC@pindar.com>
Tim wrote:

> I'm curious -- does anyone who is reading this actually teach Lisp in
> an academic context?

I don't. But, a couple of months ago I was talking to some blokes at York
University. Scheme is taught here as the compulsory undergrad language,
aparently. How out of date this teaching is I don't know (is Scheme 30
years old yet?)

:) will
From: Pierre R. Mai
Subject: Re: beginner help - string processing
Date: 
Message-ID: <87ael2ed0h.fsf@orion.dent.isdn.cs.tu-berlin.de>
William Deakin <·····@pindar.com> writes:

> Tim wrote:
> 
> > I'm curious -- does anyone who is reading this actually teach Lisp in
> > an academic context?
> 
> I don't. But, a couple of months ago I was talking to some blokes at York
> University. Scheme is taught here as the compulsory undergrad language,
> aparently. How out of date this teaching is I don't know (is Scheme 30
> years old yet?)

Around 25 years, IIRC (1975 springs to mind for some reason).

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]