Search code examples
autolisp

Autolisp user function overloading


You can read this on AutoCAD knowledge website:
"Note: You can define multiple user functions with the same name, but have each definition accept a different number or type of arguments."
Has anybody using this feature? I tried but does not work at all. I can call only the latest defined function.If I call like this (file::AppendFile arg1) then autocad said I give too less argument
enter image description here


Solution

  • "Note: You can define multiple user functions with the same name, but have each definition accept a different number or type of arguments."

    This is not possible in AutoLISP: the last defun expression evaluated will overwrite all previous definitions of the symbol in the namespace - hence, in your example the file:AppendFile function would require two arguments, as the second defun expression will immediately redefine the function.

    The only way to supply two arguments (other than supplying a list of arguments of varying length) would be to evaluate the file:AppendFile function prior to the evaluation of the second defun expression.