Search found 117 matches

by Warren Wilkinson
Thu Nov 25, 2010 4:06 pm
Forum: Common Lisp
Topic: collecting *unique* in loop
Replies: 8
Views: 7734

Re: collecting *unique* in loop

Code: Select all

(loop with result = nil
        for a in '(a b a c a d a b a c a d)
        do (pushnew a result)
        finally (return (nreverse result)))

;; result ==> (a b c d)
If you don't care about order, you don't need nreverse at the end.
by Warren Wilkinson
Wed Nov 24, 2010 7:18 pm
Forum: Common Lisp
Topic: Tips to improve my program
Replies: 1
Views: 2913

Re: Tips to improve my program

You could hardcode the sports to avoid having to do any file I/O retrieving them. You also wouldn't have to do any cleaning on them. If you have a string constant that is only used in one place, its probably better to just put it in the code body rather than a parameter. Those two changes will make...
by Warren Wilkinson
Wed Nov 24, 2010 3:54 pm
Forum: Common Lisp
Topic: loop and let
Replies: 6
Views: 5287

Re: loop and let

I don't know what to tell you, it works on my machine (SBCL 1.0.32) when I run the following: (defun foo (f) (if (evenp f) (list f) f)) (loop for f in '(1 2 3 4) as fc = (and (>= f 2) (foo f)) when (consp fc) collect fc) ;; gives ==> ((2) (4)) You could try replacing the word 'when' with 'if', what ...
by Warren Wilkinson
Wed Nov 24, 2010 1:41 pm
Forum: Common Lisp
Topic: loop and let
Replies: 6
Views: 5287

Re: loop and let

A couple of ways (loop for f in g as fc = (and (>= f tr) (foo f)) when (consp fc) collect fc) (let ((results nil)) (dolist (f g (nreverse results)) (when (>= f tr) (let ((fc (foo f))) (when (consp fc) (push fc results))))) (defun process (f) (when (> f tr) (let ((fc (foo f))) (and (consp fc) (list f...
by Warren Wilkinson
Wed Nov 24, 2010 1:31 pm
Forum: Common Lisp
Topic: Returning from a function
Replies: 1
Views: 2290

Re: Returning from a function

Looks right to me, heres a slight simplification.

Code: Select all

(defun foo
  (if (bar)
    (when (foobar) result)
    (barfoo))
If you want the result that foobar is generating (and foobar returns NIL if no result)...

Code: Select all

(defun foo (if (bar) (foobar) (barfoo)))
by Warren Wilkinson
Mon Nov 22, 2010 4:47 pm
Forum: Common Lisp
Topic: general backtracking algorithm in Lisp
Replies: 11
Views: 16326

Re: general backtracking algorithm in Lisp

Your points are clearer, it sounds like you want to apply a heuristic throughout the search --- is this by any chance a MIN/MAX algorithm for a game? Given your requirements, I would recommend against backtracking the way I've already layed out. The way I've explained it keeps everything on the stac...
by Warren Wilkinson
Mon Nov 22, 2010 3:23 pm
Forum: Common Lisp
Topic: general backtracking algorithm in Lisp
Replies: 11
Views: 16326

Re: general backtracking algorithm in Lisp

Backtracking in C (or C++) is significantly harder than it would be in Lisp, so even if you know C++ writing requirements in it might influences your thoughts. I'm not entirely sure what you mean by valuations. I'm going to restate what I think your asking and you can tell me if I've missed the mark...
by Warren Wilkinson
Mon Nov 22, 2010 11:43 am
Forum: Common Lisp
Topic: general backtracking algorithm in Lisp
Replies: 11
Views: 16326

Re: general backtracking algorithm in Lisp

Heres a real simple implementation. Given A in the range of 0 32, B in the range of 0 64, and C in the range of 0 128, it collects every combination of these 3 values that solves =128. Currently =128 is set to (= 128 (+ (* a b) c)), but could be changed. (defmacro awhen (clause &rest body) `(let...
by Warren Wilkinson
Fri Nov 19, 2010 6:02 pm
Forum: Common Lisp
Topic: Newb needs help with many things.
Replies: 6
Views: 14011

Re: Newb needs help with many things.

How you produce an executable really depends on which Lisp implementation you are using. In a few weeks I'll probably be writing a lisp application to mangle some CSV files. I'm looking into Armed Bear common lisp for this task, because I have a hunch it'll let me distribute standalone executables t...
by Warren Wilkinson
Thu Nov 11, 2010 3:35 pm
Forum: Scheme
Topic: getting constant input
Replies: 2
Views: 12299

Re: getting constant input

I/O has been sucked into operating systems for some time now, so you have to go through it. For example, on Linux ASM programs can use READ and WRITE (interrupts 3 & 4) to perform some basic IO. To do char by character input I think they must use the IOCTL system call to set the IO mode. Because...