Search found 6 matches

by vimsical
Sat Dec 03, 2011 1:09 pm
Forum: Common Lisp
Topic: a comparison sort function..
Replies: 7
Views: 8713

Re: a comparison sort function..

Yes, I believe this is the truth both in the wording and the spirit of CL. To go a bit further, but perhaps not pertinent. As I alluded to, CL is flexible enough that you don't need to do this (as say, a purely functional language wouldn't be) so there might be cases where you decide you want to wr...
by vimsical
Fri Dec 02, 2011 5:55 am
Forum: Common Lisp
Topic: a comparison sort function..
Replies: 7
Views: 8713

Re: a comparison sort function..

Using DATA after the sort is dangerous. If you are sorting a list with SORT it will probably be corrupted. When you are sorting a vector "in place", you will almost certainly use the same vector for your result, and the user might get away with using data after it has been sorted (even wh...
by vimsical
Fri Dec 02, 2011 3:58 am
Forum: Common Lisp
Topic: a comparison sort function..
Replies: 7
Views: 8713

Re: a comparison sort function..

Only other Lispy advice I can think of is that Lisp functions, by convention, try to avoid the "modify argument in place" style in preference of the "the return value is the result but the argument can no longer be considered valid" style. This doesn't mean much for your applica...
by vimsical
Thu Dec 01, 2011 11:45 pm
Forum: Common Lisp
Topic: a comparison sort function..
Replies: 7
Views: 8713

a comparison sort function..

As an exercise to LISP, I would like to write an in place sorting function to sort a simple vector of number, but I would like to make it general enough that it can also sort a vector of a list like: (vector '(1 . a) '(2 . b) '(1.5 . c)) So, I am thinking writing something like this: (defun my-sort ...
by vimsical
Thu Oct 28, 2010 12:46 am
Forum: Common Lisp
Topic: combinations
Replies: 2
Views: 3229

Re: combinations

Thanks. This is exactly what I am talking about. Usually with good LISP code, I can just read off the algorithm, instead of my spaghetti. I am a few chapter into "ANSI Common LISP" and so doesn't know all the available tools. In fact, I first tried to use (cons ... ) but got confused few t...
by vimsical
Wed Oct 27, 2010 10:18 pm
Forum: Common Lisp
Topic: combinations
Replies: 2
Views: 3229

combinations

Giving myself some exercise to learn lisp, I am writing a function display all binary strings of length N with s 1's. And I got this: ;; as(a N) return list (a a ... a) consists of N a's (defun as (a N) (if (= N 0) 'nil (append (as a (- N 1)) (list a)))) ;; Generate binary strings of N chars with s ...