Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to defun a function within a defun?

For example, I pass the function name to another function

(personal-function 'func-name '(attr1 attr2 ...))

and what I want to do is

(defun personal-function (func-name)
     (defun func-name '(attr1 attr2 ...) (dosomething)))

However, it said I can't defun with a symbol... What should I do?

like image 646
Frost Avatar asked Sep 22 '10 18:09

Frost


People also ask

Can you call a function within a function?

Calling a function from within itself is called recursion and the simple answer is, yes.

Can I define a function within a function in JavaScript?

A function is called “nested” when it is created inside another function. It is easily possible to do this with JavaScript. Here the nested function getFullName() is made for convenience. It can access the outer variables and so can return the full name.

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 does defun mean in Lisp?

In Lisp, a symbol such as mark-whole-buffer has code attached to it that tells the computer what to do when the function is called. This code is called the function definition and is created by evaluating a Lisp expression that starts with the symbol defun (which is an abbreviation for define function).


1 Answers

Use

(setf (symbol-function my-symbol) some-function)

create a new function with

(compile nil (list 'lambda args body))

where args and body have meaningful values.

like image 159
Rainer Joswig Avatar answered Oct 01 '22 04:10

Rainer Joswig