Application Scenario: the backend of a statistical queryProgramThe corresponding processing functions are called Based on the query name string.
In general, you can use a Global Registry to match the name string with the function name. However, LISP programmers are very lazy. Since the lisp environment itself already provides a name registration mechanism, why do we need to write one? In fact, the core of the lisp environment lies in namespace.
The solution is as follows:
<Br/> (defun Q-Hello () <br/> (format t "Q-Hello OK") <br/> (defun Q-World () <br/> (format t "Q-world OK") <br/> (defun call-by-Name (name) <br/> (funcall (Nth-value 0 (read-from-string name ))))
Run the following command:
CL-user (34): (call-by-name "Q-Hello ") <br/> q-Hello OK <br/> nil <br/> Cl-user (34): (call-by-name "Q-WORLD ") <br/> q-world OK <br/> Nil
This is the first step, but no exception processing is performed. For example, if a non-existent function is called, The system reports an exception.
To be continued ..