Search found 117 matches

by Warren Wilkinson
Thu Sep 02, 2010 10:13 am
Forum: The Lounge
Topic: Question about parentheses
Replies: 27
Views: 55246

Re: Question about parentheses

I use a non-standard dvorak varient called Programmers Dvorak http://www.kaufmann.no/roland/dvorak/ . I further modified it by swapping 'u' and 'i', and making CAPSLOCK just a third CTRL button. My parenthesis are under keys '5' and '8', but I don't have to hold shift to get them. This is a file I c...
by Warren Wilkinson
Thu Sep 02, 2010 9:21 am
Forum: Common Lisp
Topic: averaging
Replies: 12
Views: 11018

Re: averaging

Yeah, I use that too --- Its often inconvenient that last returns a list rather than an item. Maybe I'll just define a utility function

Code: Select all

(defun last-item (list) (car (last list)))
and be done with it.
by Warren Wilkinson
Wed Sep 01, 2010 11:59 pm
Forum: Common Lisp
Topic: Equivalent of shlex.slpit of python in common-lisp
Replies: 5
Views: 5791

Re: Equivalent of shlex.slpit of python in common-lisp

I actually wrote a blog post on writing parsers: http://formlis.wordpress.com/2010/07/07/flexible-parsing-without-regexps/ . This operation is non-trivial; there are three 3 states: Reading Text, Skipping Whitespace, and Handling Quotes. There are also three diferent character classes: Regular chara...
by Warren Wilkinson
Wed Sep 01, 2010 11:26 pm
Forum: Common Lisp
Topic: mapcar or notmapcar
Replies: 11
Views: 9645

Re: mapcar or notmapcar

Why would you want floats/decimal numbers? You could opt to use the more accurate rational numbers throughout your code and then use format's "~f" operator to print the result as a floating point number.
by Warren Wilkinson
Wed Sep 01, 2010 1:13 pm
Forum: Common Lisp
Topic: averaging
Replies: 12
Views: 11018

Re: averaging

Now here is a working 'reduce' example: (defun average (lst) (/ (reduce #'+ lst :key #'(lambda (x) (first (last x)))) (length lst))) The :key argument tells 'reduce' to which element from the lists inside 'lst' the '+' function shall be applied. Because 'last' returns the last element as a list, th...
by Warren Wilkinson
Wed Sep 01, 2010 1:09 pm
Forum: The Lounge
Topic: Lisp as assembly language??
Replies: 12
Views: 45755

Re: Lisp as assembly language??

I'll yield the point on the names of CAR and CDR. I thought they were a Lisp machine terminology for some dedicated hardware that performed list operations. But my point was never that register machines can't host Lisp, but that their base vocabulary is orthogonal to Lisp. If you want a low-level Li...
by Warren Wilkinson
Wed Sep 01, 2010 12:55 pm
Forum: Common Lisp
Topic: mapcar or notmapcar
Replies: 11
Views: 9645

Re: mapcar or notmapcar

Code: Select all

(defun operation (f-list s-list)
  (/ (reduce #'+ (mapcar #'* f-list s-list)) (reduce #'+ s-list)))

(operation '(1 2 3 4) '(5 6 7 8))  ;; gives 35/13

by Warren Wilkinson
Mon Aug 30, 2010 3:53 pm
Forum: Common Lisp
Topic: can u help me to solve this ...plzzz
Replies: 4
Views: 8674

Re: can u help me to solve this ...plzzz

Well, not anything too interesting. The results are highly dependent on the heuristic for deciding 'best'. For example, a set of coins that had denominations for 1, 2, 3, 4, 5, 6 ... , 97, 98, 99, 100 would perform well -- only 1 coin is ever needed. If you add a cost for the number of unique coins,...
by Warren Wilkinson
Mon Aug 30, 2010 3:21 pm
Forum: Common Lisp
Topic: stuck
Replies: 14
Views: 11749

Re: stuck

Here are 5 ways of doing it. I added timing for SBCL on my computer without tweaking any optimization stuff. ;; using a reduction (defun odd-count1 (list) (reduce #.(lambda (acc i) (if (oddp i) (1+ acc) acc)) list :initial-value 0)) ;; using 'loop' (defun odd-count2 (list) (loop for i in list counti...
by Warren Wilkinson
Sun Aug 22, 2010 10:20 am
Forum: Common Lisp
Topic: can u help me to solve this ...plzzz
Replies: 4
Views: 8674

Re: can u help me to solve this ...plzzz

I actually did this yesterday. I wanted to run a genetic algorithm to see what set of 'coins denominations' made for the least amount of change. Anyway, here was mine: (defun currency (a amounts results) (if (null amounts) (nreverse (cons a results)) (multiple-value-bind (n remainder) (truncate a (c...