Subject: Re: Newbie - 2 MORE Small problems?
From: Erik Naggum <erik@naggum.net>
Date: Sun, 10 Mar 2002 20:40:17 GMT
Newsgroups: comp.lang.lisp
Message-ID: <3224781627311493@naggum.net>

* TejimaNoHimitsu <bleh@test.com>
| The above function is supposed to take a predicate, a number, and a
| sorted list of numbers and insert elm into lis at the proper spot
| based on the boolean predicate p.  For example, if you call:
| 
| (insert-n-sort #'< 3 '(2 4 6 8))
| 
| You should get
| 
| (2 3 4 6 8)  back.

  Not to spoil your fun here, but either of these will produce the correct
  result with very little overhead:

(merge 'list (list 3) (list 2 4 6 8) #'<)
(sort (list* 3 (list 2 4 6 8) #'<))

  Please note that sort is destructive, so do not use a quoted argument.

| 1)  How can I change all the setf crap to let statements?  I know it's
| bad form to use setf

  setf is not bad form.  It is bad karma to teach that it is.  Your
  professor may return as a Scheme programmer if he keeps this up.  (Or he
  may done something terrible in his previous life and actually be a Scheme
  programmer.)
 
  It _is_ bad form to setf a component of a quoted constant, however.

|  I can never get the syntax for let working properly...

  It is really quite simple: (let (<binding>*) <declaration>* <form>*).
  A <binding> has the form (<variable> <value>), or just <variable> if you
  plan to set it before you use it.

| 2)  Is there an easy way to sort the list produced by the mapcar?  By
| easy, I don't mean calling (sort timp #'<)  because we aren't allowed to
| use the sorting function.  In fact, we shouldn't even need to sort the
| list... but that's the only way I can get it to work.  Program is a piece
| of cake in Java, C++, C#, etc.... but I don't know lisp well enough to do
| something like a minsort (hence why I asked how to swap elements)  ;)

  I am so strongly opposed to the pointless exercises in re-inventing the
  wheel using idiotic restrictions in order to learn what a wheel is that I
  think teachers who do this to their students should be terminated.

  Having to reimplement basic functionality is not as illuminating as
  reading and understanding a professional programmer's implementation of
  it -- "learn by doing" is good for muscular training.  Programming is a
  process of thinking, so you learn by thinking, not by unthinkingly
  replicating the mere results of other people's thinking.  I also think
  every writer learns to write by reading observantly, taking notes, using
  a very large dictionary to discover nuances and details in meaning, and
  paying attention to details everywhere.  I think this is what studying is
  all about -- learning merely to repeat what others have done before you
  is not study.

| I know I asked for help once already so I understand if people are
| reluctant to provide more aid....

  As long as they keep learning and ask intelligent questions and work on
  your own, it is actually a joy to help people.

///
-- 
  In a fight against something, the fight has value, victory has none.
  In a fight for something, the fight is a loss, victory merely relief.