wimal Posted January 13, 2019 Posted January 13, 2019 Two lisp programs loaded.There are same defun names (but deference codes)in those programs. When I use the command of first program it working. But when I use command of second program, it running as first program. If I load and run the second program, it is ok. Can you give me an idea to solve this. Quote
dlanorh Posted January 13, 2019 Posted January 13, 2019 What are the defun names? Are they both (defun c:???) is so then rename one of them. Quote
wimal Posted January 13, 2019 Author Posted January 13, 2019 It can do as you say. But I need some other method. Because too meany name I have to change. Quote
dlanorh Posted January 13, 2019 Posted January 13, 2019 There is no other option. With two functions named the same, the last one loaded will replace the first one loaded. So you need to rename one or continually reload the one you need. Find a decent notepad replacement that has a "Replace" command (Notepad++). This will allow you to highlight the first occurance of the string, specify the string to replace it (whole word only option) and replace every occurance of that string in the file in one go or on a string by string basis. Even using string by string it's a whole lot faster than finding each occurance and manually changing each one. Quote
Grrr Posted January 13, 2019 Posted January 13, 2019 Alternatively you could define separate scopes - For instance you have defined these functions: (defun C:test ( / ) (alert (strcat (alerting) ", guys")) (princ) ) (defun alerting nil "Hello" ) (defun C:test ( / ) (alert (strcat (alerting) ", there")) (princ) ) (defun alerting nil "Hi" ) You can wrap them in defuns with different names, but localise all the functions and subfunctions within: (defun C:test1 ( / C:test alerting ) (defun C:test ( / ) (alert (strcat (alerting) ", guys")) (princ) ) (defun alerting nil "Hello" ) (C:test) (princ) ) (defun C:test2 ( / C:test alerting ) (defun C:test ( / ) (alert (strcat (alerting) ", there")) (princ) ) (defun alerting nil "Hi" ) (C:test) (princ) ) Thats one of the reasons I keep my smaller subs localised, since they are generic and I might have been used similar in other .lsp file - like this one: (setq fill_listbox (lambda (k L) (start_list k) (mapcar 'add_list L) (end_list))) And other subfunctions of mine that are 200+ rows and almost no risk of me to overwrite them, as global - such as "MergePDFs" or "AddMyLayers". 2 Quote
BIGAL Posted January 15, 2019 Posted January 15, 2019 (edited) Its maybe time to think about a index list what defun is used with which program. You could use a lisp to look for "defun" in a list of lisps, reading each line as it is a text file then write filename and defun name and so on. Do this first from Windows type CMD open the command window use the old fashioned DOS and change to your lisp directory Type findstr defun *.lsp >defunlist.txt and all should be revealed when you open defunlist.txt. Edited January 15, 2019 by BIGAL 1 Quote
Grrr Posted January 15, 2019 Posted January 15, 2019 (edited) One could use a wrapper like this, although It won't make any sense because if one knows how to properly use it will also know how to properly define his functions. (defun DefineScope ( fn call body / args ) (setq args (cons '/ (mapcar 'eval body))) (foreach x (cdr args) (if (/= (substr (vl-symbol-name x) 1 2) "C:") (set x nil) ) ) (eval (cons 'defun (append (list fn args) body call '((princ))))) ); defun DefineScope Sample usage: (DefineScope 'C:test1 '( (alert "Now calling (test1) and (test2) \nand defining (C:testfoo)") (test1) (test2) ) '( (defun C:testfoo nil (alert "I'm testfoo,\n and I'm not dependent on the internal subfunctions") (princ) ) (defun test1 ( / ) (mySub1 "Hi") ) (defun test2 ( / ) (mySub2 "Hello") ) (defun mySub1 (x) (alert x) ) (defun mySub2 (x) (alert (strcat x ", there")) ) ); list ); DefineScope (DefineScope 'C:test2 '( (alert "Now calling (test1) and (test2)") (test1) (test2) ) '( (defun test1 ( / ) (mySub1 "Hi") ) (defun test2 ( / ) (mySub2 "Hello") ) (defun mySub1 (x) (alert (strcat x " guys")) ) (defun mySub2 (x) (alert (strcat x ", all")) ) ); list ); DefineScope So basically whats defined within the body that doesn't have the "C:" prefix will be private - test1 >> nil test2 >> nil mySub1 >> nil mySub2 >> nil c:test1 >> #<USUBR @0000008065e772f0 C:TEST1> c:test2 >> #<USUBR @0000008065e77548 C:TEST2> C:testfoo >> #<USUBR @0000008065e77098 C:TESTFOO> Edited January 15, 2019 by Grrr Quote
Steven P Posted January 16, 2019 Posted January 16, 2019 Ideally you would rename one or the other LISP. If the LISP with the duplicated name is called / run from another LISP as a subroutine you could simply reload the file containing the duplicate named LISP as required and make it the most recent one to be loaded. Use a line similar to this. (load "-filepath and LISP file name remember to use \\ insted of single \ as required - " "LISP Failed to Load") So long as the file name and location won't change this should work - not ideal mind, 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.