Skip to content

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Brandenburg committed May 15, 2010
0 parents commit 0a696f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Empty file added README
Empty file.
5 changes: 5 additions & 0 deletions gp.asd
@@ -0,0 +1,5 @@
(asdf:defsystem :gp
:depends-on ()
:serial t
:components
((:file "gp")))
26 changes: 26 additions & 0 deletions gp.lisp
@@ -0,0 +1,26 @@
(defpackage #:gp.goof
(:use :cl)
(:documentation "Genetic programming is cool!"))

(in-package :gp.goof)

; Look! A Y Combinator.
(defun Y (r)
((lambda (f) (funcall f f))
(lambda (f)
(funcall r (lambda (x) (funcall (funcall f f) x))))))

; So apparently labels is better than Y, but I'm keeping the Y.
(defun mutate (form)
"Mutate takes a form and modifies the numbers randomly."
(let ((sign (let ((x (random 2)))
(if (= x 0) #'+ #'-))))
(mapcar (Y (lambda (fun)
(lambda (n)
(cond
((eq (class-of n) (find-class 'fixnum))
(funcall sign (random 5) n))
((eq (class-of n) (find-class 'cons))
(mapcar fun n))
(t n)))))
form)))

0 comments on commit 0a696f6

Please sign in to comment.