A little lisp program i got to write should do the following (copied from my old question: LISP - Program to search a specific function through its parameters):
The program should work in 2 different ways:
You give the program the name of a function and it should return the function parameters.
You enter function parameters and if a function with these parameters exists, it should return the name of the function.
I got the following code:
(defun get-name-by-params (database params)
(let ((matching-entries (remove-if-not (lambda (entry)
(equal (second entry) params))
database)))
(mapcar #'first matching-entries)))
(defun get-params-by-name (database function)
(let ((matching-entries (remove-if-not (lambda (entry)
(equal (first entry) function))
database)))
(flatten(mapcar #'second matching-entries))))
(defun flatten (L)
(if (null L)
nil
(if (atom (first L))
(cons (first L) (flatten (rest L)))
(append (flatten (first L)) (flatten (rest L))))))
With that code i get the following results:
(get-params-by-name '((cons (t t) cons) (list (&rest t) list) (append (&rest lists) result)) 'append)
->(&REST LISTS)
(get-name-by-params '((cons (t t) cons) (list (&rest t) list)) '(&rest t))
->(LIST)
That is in both cases exactly what i need. My last problem with my task is that i need to create a database in which the functions and parameters are stored because i will need to add many more functions to the program.
So i need to create a database which stores the following data
'((cons (t t) cons) (list (&rest t) list) (append (&rest lists) result))
and, if possible, can be processed by the given functions.
Could anybody please give me an example how to create a database for this task?