From: Pascal J. Bourguignon on
Wade <wade.humeniuk(a)gmail.com> writes:

> Sorted lists are your friend
>
> (defun count-sorted-list (list)
> (when list
> (let ((element (car list))
> (n 1))
> (loop for next on (cdr list)
> while (eql element (car next)) do (incf n)
> finally (return (cons (cons element n)
> (count-sorted-list next)))))))
>
> (defun count-list (list)
> (sort
> (count-sorted-list (sort (copy-list list) #'string<))
> #'>
> :key #'cdr))
>
> CL-USER> (count-list '(a b c f g a a c c a b ))
> ((A . 4) (C . 3) (B . 2) (F . 1) (G . 1))
> CL-USER>

For a small list it wouldn't matter, but for a big list, your first
sort would increase your processing time by log(n).

Moreover, you need to copy the list, so it doubles the space needed.


Nothing that cannot be solved by putting more money on it, but if you
have a $1M super computer to process, perhaps you won't want to spend
$1M more for an extension.

Of course, if you're running it on a small list on a $50 computer, you
could indeed as well buy a $200 computer and have it run twice as
fast, you will hardly notice the difference.

--
__Pascal Bourguignon__ http://www.informatimago.com/
From: Tamas K Papp on
On Fri, 18 Jun 2010 23:05:50 -0400, Bob Felts wrote:

> Absolutely. In my opinion, one's first introduction to computers should
> be about problem representation and abstraction of problem elements,
> only then to be followed by programming languages.

In my opinion, learning should be enjoyable. Maybe that's just me,
but if I don't enjoy learning something, I won't do it well. So if my
_first_ introduction to computers was an abstract course without any
practical programming, I might have lost interest.

Fortunately for me, I am self-taught in programming, so it was easy to
negotiate the contents of the course with the instructor :-)

OTOH, I don't deny the usefulness of the things you mention, I just
don't think that they are that useful when one is first introduced to
computers.

Best,

Tamas
From: Captain Obvious on
??>> Piling complication on top of this simple abstraction could make sense
??>> in the context of advanced application design, but is it good
??>> paedagogy for beginners?

R> Of course it is. Why would you doubt it?

Your choice of abstractions are arbitrary.
You've abstracted out hash-table, but you didn't abstract out lists.
So your code is not consistent and it is a bad example. (Unless you're
willing to teach inconsistency.)

From: Bob Felts on
Tamas K Papp <tkpapp(a)gmail.com> wrote:

> On Fri, 18 Jun 2010 23:05:50 -0400, Bob Felts wrote:
>
> > Absolutely. In my opinion, one's first introduction to computers should
> > be about problem representation and abstraction of problem elements,
> > only then to be followed by programming languages.
>
> In my opinion, learning should be enjoyable. Maybe that's just me,
> but if I don't enjoy learning something, I won't do it well. So if my
> _first_ introduction to computers was an abstract course without any
> practical programming, I might have lost interest.
>
> Fortunately for me, I am self-taught in programming, so it was easy to
> negotiate the contents of the course with the instructor :-)
>
> OTOH, I don't deny the usefulness of the things you mention, I just
> don't think that they are that useful when one is first introduced to
> computers.

I wish I could disagree with you, but your point is sound. I'm just
overly grouchy from having to deal with code written by people who never
get past the "drawing outside the lines with crayons" stage.
Programmers are like American Idol contestents. The majority who think
they can sing simply can't.
From: RG on
In article <4c1c9bb4$0$274$14726298(a)news.sunsite.dk>,
"Captain Obvious" <udodenko(a)users.sourceforge.net> wrote:

> ??>> Piling complication on top of this simple abstraction could make sense
> ??>> in the context of advanced application design, but is it good
> ??>> paedagogy for beginners?
>
> R> Of course it is. Why would you doubt it?
>
> Your choice of abstractions are arbitrary.

No, it isn't. Abstract associative maps have a unique combination of
simplicity and power, not unlike cons cells. In fact, you can think of
an abstract associative map as a generalization of a cons cell with an
arbitrary number of cells that you can give arbitrary names.

> You've abstracted out hash-table, but you didn't abstract out lists.

So?

> So your code is not consistent and it is a bad example. (Unless you're
> willing to teach inconsistency.)

Huh? I have no idea what you mean by that.

rg