Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function names as strings in Lisp?

I have a big list of global variables that each have their own setup function. My goal is to go through this list, call each item's setup function, and generate some stats on the data loaded in the matching variable. However, what I'm trying now isn't working and I need help to make my program call the setup functions.

The global variables and their setup functions are case-sensitive since this came from XML and is necessary for uniqueness.

The data looks something like this:

'(ABCD ABC\d AB\c\d ...)

and the setup functions look like this:

(defun setup_ABCD...  
(defun setup_ABC\d...

I've tried concatenating them together and turning the resulting string into a function, but this interferes with the namespace of the previously loaded setup function. Here's how I tried to implement that:

(make-symbol (concatenate 'string "setup_" (symbol-name(first '(abc\d)))))

But using funcall on this doesn't work. How can I get a callable function from this?

like image 885
ktdh Avatar asked Nov 17 '08 02:11

ktdh


People also ask

How do you define a function in a Common Lisp?

Use defun to define your own functions in LISP. Defun requires you to provide three things. The first is the name of the function, the second is a list of parameters for the function, and the third is the body of the function -- i.e. LISP instructions that tell the interpreter what to do when the function is called.

What is SETQ in LISP?

(setq var1 form1 var2 form2 ...) is the simple variable assignment statement of Lisp. First form1 is evaluated and the result is stored in the variable var1, then form2 is evaluated and the result stored in var2, and so forth. setq may be used for assignment of both lexical and dynamic variables.

What does Setf do in LISP?

setf is actually a macro that examines an access form and produces a call to the corresponding update function. Given the existence of setf in Common Lisp, it is not necessary to have setq, rplaca, and set; they are redundant. They are retained in Common Lisp because of their historical importance in Lisp.

How do you compare two strings in LISP?

To compare the characters of two strings, one should use equal, equalp, string=, or string-equal. Compatibility note: The Common Lisp function eql is similar to the Interlisp function eqp.


1 Answers

It's because MAKE-SYMBOL returns an uninterned symbol. You should use INTERN instead.

like image 197
Nowhere man Avatar answered Oct 17 '22 20:10

Nowhere man