Next: Evaluation, Previous: Examples, Up: Examples [Contents][Index]
The sel:mutate method applies a random mutation to a
sel:software object and returns two values: the mutated
object and a sel:mutation object describing the mutation
that was applied.
The following example applies a random mutation to gcd.s.
sel:from-file to load gcd.s into a new sel/sw/asm:asm software object, orig.
sel:mutate to mutate a deep sel:copy of orig.
sel:to-file.
sel:mutation that was applied.
(defpackage :example
(:use :gt/full
:software-evolution-library
:software-evolution-library/software/asm))
(in-package :example)
;;; gcd.s may be compiled from gcd.c in the test/ directory.
;; create an ASM software object using `from-file'
(defvar *orig* (from-file (make-instance 'asm) "test/etc/gcd/gcd.s"))
;; the results of `mutate' are a mutated object MUTANT and a `mutation' EDIT
(multiple-value-bind (mutant edit)
(handler-bind
((no-mutation-targets
(lambda (e)
(declare (ignorable e))
(invoke-restart 'try-another-mutation))))
(mutate (copy *orig*)))
(let ((temp (temp-file-name :type "s")))
;; save MUTANT to temp file TEMP
(to-file mutant temp)
(format t "Results of applying ~S to gcd written to ~S~%"
edit temp)))
Executing this code will print output resembling the following.
Results of applying #<SIMPLE-CUT #<ASM #x3020022A24DD> 78> to gcd written to "/\ tmp/fileLfs6Mf.s".
sel/sw/asm:asm