Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial import.

  • Loading branch information...
commit 0a696f689b01834bd695e301fed9b13244e015df 0 parents
Martin Brandenburg authored
Showing with 31 additions and 0 deletions.
  1. 0  README
  2. +5 −0 gp.asd
  3. +26 −0 gp.lisp
0  README
No changes.
5 gp.asd
@@ -0,0 +1,5 @@
+(asdf:defsystem :gp
+ :depends-on ()
+ :serial t
+ :components
+ ((:file "gp")))
26 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)))
Please sign in to comment.
Something went wrong with that request. Please try again.