How to include a file

Discussion of Common Lisp
smithzv
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am

Re: How to include a file

Post by smithzv » Wed May 19, 2010 1:06 pm

Well, here is my take on what you are asking.

You are writing a genetic program. You have your population stored in a file, each member of your population is represented as a list. You want a way to pass all of that data to the function run-genetic-programming-system. As things are currently set up run-genetic-programming-system takes a symbol (name of a fitness function?), a random number, some other number (number of generations to run for?) and the population as a &rest argument. Presumably your code either returns the new population perhaps sorted by fitness (good) or writes that new population to a file (less good).

You can slurp up an entire file like Ramarren showed (using iterate):

Code: Select all

(iter (for list in-file file)
      (collect (second list)) )
Then you may pass it as an argument to run-genetic-programming-system by using apply. So you could write what you want to do as:

Code: Select all

(with-open-file (stream file)
  (apply #'run-genetic-programming-system
         'area-circle (random 100.0) 10000
         (iter (for list in-file file)
               (collect (second list)) )))
However, since the length of arglists are limited, you should probably not pass your population (which can be large) as a &rest parameter, but explicitly as a list.

Code: Select all

(with-open-file (stream file)
  (run-genetic-programming-system
   'area-circle (random 100.0) 10000
   (iter (for list in-file file)
         (collect (second list)) )))
But you have to change run-genetic-programming-system first. Hope something here helps and that I'm not completely off base.

Post Reply