Archived

This topic is now archived and is closed to further replies.

help regarding lisp

This topic is 4987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to implement a basic genetic programming system in Lisp. The general goal is to have an end function f(x) with a predefined set of inputs mapping to outputs. My GP must come reasonably close to this. f must utilize a set of operators. What I''d like to do is in the initialization step randomly choose a set of operators, set them up in the test-f function, and run the test-set of criteria, and so forth. Now to the Lisp end of the problem. I''d like to do something like this:
(setq func-list (list 
   (defun add (a b) (+ a b)) 
   (defun sub (a b) (- a b))
  ...
))
 
Then somewherein my test-func I would have something along these lines: ((nth (rand-val-in-range 0 max) funclist) value) I don''t know how to get that to work. I keep getting told the first value is not a function name, which it really is... Arg. Any ideas on how to do this?

Share this post


Link to post
Share on other sites
I'm not sure of the proper technical terms, but put simply, Lisp doesn't evaluate the 'function place' in an expression. In order to use a function that is the result of some calculation, you need to use funcall or apply depending on your exact needs. You could also use eval, but it is probably more than you need and its use is generally frowned upon.

Also, if you aren't using the names of the functions, you might as well use anonymous functions something like
(setq func-list (list
(lambda (a b) (+ a b))
(lambda (a b) (- a b))
...
))
that way you don't needlessly fill the namespace with function names you never use.

[edited by - Extrarius on April 23, 2004 3:23:20 AM]

Share this post


Link to post
Share on other sites