Next: , Previous: , Up: Examples   [Contents][Index]


5.2.1 Mutation

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.

  1. Uses sel:from-file to load gcd.s into a new sel/sw/asm:asm software object, orig.
  2. Applies sel:mutate to mutate a deep sel:copy of orig.
  3. Writes the mutated object to disk with sel:to-file.
  4. Prints the 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".

API components in this example