Re: How to include a file
Posted: 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):
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:
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.
But you have to change run-genetic-programming-system first. Hope something here helps and that I'm not completely off base.
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)) )
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)) )))
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)) )))