;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.genetic-programming) ;;;;;; ;;; Function descriptor (def special-variable *function-descriptors* (make-hash-table)) (defstruct function-descriptor (name nil :type symbol) (return-type nil :type t) (argument-types nil :type list)) (def (function e) find-function-descriptor (name) (check-type name symbol) (the (or null function-descriptor) (gethash name *function-descriptors*))) (def (function e) (setf find-function-descriptor) (function-descriptor name) (check-type name symbol) (check-type function-descriptor function-descriptor) (setf (gethash name *function-descriptors*) function-descriptor)) (def (definer e) function-descriptor (name argument-types return-type) `(setf (find-function-descriptor ',name) (make-function-descriptor :name ',name :argument-types ',argument-types :return-type ',return-type))) (def (function e) collect-function-descriptors (names) (mapcar 'find-function-descriptor names)) (def (function e) collect-matching-function-descriptors (return-type argument-types function-descriptors) (remove-if-not (lambda (function-descriptor) (and (subtypep (function-descriptor-return-type function-descriptor) return-type) (or (not argument-types) (and (length= argument-types (function-descriptor-argument-types function-descriptor)) (every (lambda (function-argument-type argument-type) (subtypep function-argument-type argument-type)) (function-descriptor-argument-types function-descriptor) argument-types))))) function-descriptors)) ;;;;;; ;;; Predefined function descriptors (def function-descriptor not (boolean) boolean) (def function-descriptor or (boolean boolean) boolean) (def function-descriptor and (boolean boolean) boolean) (def function-descriptor = (number number) boolean) (def function-descriptor /= (number number) boolean) (def function-descriptor < (number number) boolean) (def function-descriptor <= (number number) boolean) (def function-descriptor > (number number) boolean) (def function-descriptor >= (number number) boolean) (def function-descriptor + (number number) number) (def function-descriptor - (number number) number) (def function-descriptor * (number number) number) (def function-descriptor / (number number) number) (def function-descriptor min (number number) number) (def function-descriptor max (number number) number) (def function-descriptor sqrt (number) number)