From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!deine.net!hamster.europeonline.net!newsfeed.europeonline.net!nslave.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader3.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: Newbie - 2 MORE Small problems? References: <91B767C5406A2E5D.5706A96A8B156A73.008B5E36E251D3CE@lp.airnews.net> <3224720776260433@naggum.net> <0fbn8us36rts6j6oc753pe7lhtj9421hb2@4ax.com> Mail-Copies-To: never From: Erik Naggum Message-ID: <3224781627311493@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 67 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 10 Mar 2002 20:40:17 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader3.kpnqwest.net 1015792817 193.71.199.50 (Sun, 10 Mar 2002 21:40:17 MET) NNTP-Posting-Date: Sun, 10 Mar 2002 21:40:17 MET Xref: archiver1.google.com comp.lang.lisp:28376 * TejimaNoHimitsu | 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 (*) *
*). A has the form ( ), or just 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.