I'm trying to adapt this defstruct example by adding the select- functions described in the book: Practical Common Lisp. I'm running the code in Emacs using the Common Lisp package. The select-by-first does not return anything. In the Lisp book, the author does not use defstruct so I must need to do something slightly different?
(defun select-by-first (first-name) (remove-if-not #'(lambda (employee) (equal (getf employee :first-name) first-name)) *emp-db*)) (select-by-first "steve")
The complete program:
(require 'cl)
;; http://mypage.iu.edu/~colallen/lp/node56.html
;; http://www.gigamonkeys.com/book/practical-a-simple-database.html
;;
(defvar *emp-db* nil)
(defun add-record (emp) (push emp *emp-db*))
(defstruct employee
age
first-name
last-name
sex
children)
(add-record (make-employee))
(add-record (make-employee
:age 34
:last-name 'farquharson
:first-name 'alice
:sex 'female))
(add-record (make-employee
:age 43
:last-name 'jobs
:first-name 'steve
:sex 'male))
(add-record (make-employee
:age 53
:last-name 'ballmer
:first-name 'steve
:sex 'male))
(defun select-by-first (first-name)
(remove-if-not
#'(lambda (employee)
(equal (getf employee :first-name) first-name))
*emp-db*))
(select-by-first "steve")