Masud Rana
Masud Rana

Reputation: 3

Lisp function exists or not checking

I want to check a function definition exists in a lisp program or not to decide which program block to run. The function definition is written on another file with.Net & I am working for AutoCAD. Please help.

Upvotes: 0

Views: 1593

Answers (2)

Dinesh Vilas Pawar
Dinesh Vilas Pawar

Reputation: 493

Lee's Answer is great, many time to check function is loaded or not I am use (and functionName) it return T if exist or if not returns Nil.

Upvotes: 0

Lee Mac
Lee Mac

Reputation: 16035

There are many ways to do this, but ultimately you need to check whether the symbol corresponding to the function name holds a value (for example using the boundp function), and perhaps additionally whether such value is of SUBR, USUBR, or EXRXSUBR data type (using the type function).

For example:

(member (type YourFunctionName) '(subr usubr exrxsubr))

In this case, if the symbol YourFunctionName is null, (type YourFunctionName) will return nil which will cause the member expression to return nil. Similarly, if the value held by the YourFunctionName symbol is anything other than a function, the member function will return nil.

Since any non-nil value in AutoLISP is interpreted as True, the use of member will validate an if test expression, even though member does not explicitly return a boolean value.

Upvotes: 2

Related Questions