elisp - Using a defstruct database with remove-if-not -


I am trying to customize this example by adding the select - functions described in the book :. I am running the code in MX using the normal Lisp package. Select-By-First does not return anything In the Lips book, the author does not use defstruct, so I need to separate a bit if the no-no # (Lambda (employee) (Getf employee: first name) first name) * emp-db *) (first select "steve")

Complete program:

  ('cl' is needed) ;; Http://mypage.iu.edu/~colallen/lp/node56.html ;; Http://www.gigamonkeys.com/book/practical-a-simple-database.html ;; (Defvar * emp-db * zero) (defun add-record (emp) (push emp * emp-db *)) (employee age first name last name sexually defstruct sex)  
 
  Bye-first (custom Name) (remove-if-not # '(Lambda (employee) (equal (getf employee: first name) first name)) * emp-db *) (first by selecting "Steve")  

There are some basic mistakes / problems but with only two small changes we get your example to work in common Lisp can do.

  • Imax Lisp's Compatibility Package for General Lisp is not really a common Lisp, it is generally better to use a real common Lisp implementation. Emacs Lisp has some basic things that make it difficult to simulate to make it compatible with common Lisp - for example Lexical Closer (Update 2014, the latest version of GNU MX is still going to stop writing Minor changes: I've changed your example so that Steve Jobs may not be included twice in the database, but Steve Jobs and Steve Ballmer.

(getf employee: first name) must be really (employee-employee named first), what will happen now?

  • DEFSTRUCT Macro automatically generates these accessor functions In normal lists, you can not use GETF to reach the real infrastructure area.
  • In your database there are two objects with Steve (a symbol) name, but you are searching for the name "Steve" (a string) (equals "Steve" Steve ) Is wrong, generally a symbol is not equal to the string. So you should search with it (first by selecting 'Steve).

  • Then in LispWorks:

      CL-User 11 & gt; ("Steve" first by selection) Zero CL-User 12 & gt; (Selection-by-first 'Steve) (#S (employee: age 53: first name, Steve: last name baller: gender man: hair blue) #S (employee: age 43: first name Steve: Name job: having sex: hair blue))  

    Comments

    Popular posts from this blog

    sql - dynamically varied number of conditions in the 'where' statement using LINQ -

    asp.net mvc - Dynamically Generated Ajax.BeginForm -

    Debug on symbian -