Jump to content

Name of LISP Program Running


Recommended Posts

Posted

I'm trying to compartmentalize some modules to be used in more than one program. Certain variables would be set based on the name of the LISP program currently running. Is there a way to determine the name of the currently running LISP program programatically?

Posted

When you access a module from the current LISP, you can also pass arguments to it, including the name of the current LISP.

Posted

Unfortunately ALisp does not have something equivalent to a C programs args[0] parameter. It simply loads the LSP file directly into the system. So you've got the 2 choices:

 

  1. As Lee's shown, use a reactor to set some variable when the LSP file is loaded.
  2. Add a line of code setting a global variable inside the LSP file which is loading.

The only place I know of which has anything close to this automatically is if you've compiled your LSP's into VLX files, e.g.: vl-list-loaded-vlx.

 

Unfortunately none of those will be able to tell you exactly where the currently running code came from originally. I'm not even aware of anything which gives you a listing of currently running defun names. If that was possible you could design the reactor / global var ideas to incorporate some assoc list to check where the current/nested defun was loaded from.

 

Edit: Of course this might not be necessary, depending on your requirements. E.g. say you want to check if something is loaded already. All you need to do is check if a variable or defun (which came from that LSP file) is already in memory - use an if statement with the var/defun's name (if it's not loaded it will evaluate to nil). Something like this:

(if (not MyDefun)
 (load "MyLispFile"))

Posted

There are three reactors pertaining to lisp I'm aware of for vlr-lisp-reactor - :vlr-lispWillStart :vlr-lispEnded :vlr-LispCancelled.

All three reactors feed two pieces of information (vars) to your recieving function (reactorObj and info). reactorObj is a standard reactor object, but I'm a little fuzzy on the info, other than you'll need the (car info).

 

Afralisp.net to get your feet wet on reactors, and then here's an example.

 

 

;note: my original goal was to remove reactors when particular lisp was running
;                     *******example code only************
;so all these reactors are calling the same function.
;in that function I will decide what to do.
(defun cd:ReactAdd ()
 (vlr-lisp-reactor "cdLispHide" '((:vlr-lispWillStart . cd:rCD2LaySave)))
 (vlr-lisp-reactor "cdLispRestore" '((:vlr-lispEnded . cd:rCD2LaySave)))
 (vlr-lisp-reactor "cdLispCancel" '((:vlr-lispCancelled . cd:rCD2LaySave)))
 (princ "\nReactors Added")
 );defun cd:ReactAdd

(defun cd:rCD2LaySave (rObj info /
        rName rCmd
        RestoreLisp HideLisp LispWatch
        )
 (setq RestoreLisp "cdLispRestore,cdLispCancel")
 (setq HideLisp "cdLispHide")
 (setq LispWatch "(C:CONVERTSOLID),(C:CONVERTDOUBLE),(C:CONVERTSINGLE),(C:CONVERTISO),(GETLAY)")
 ;other categories can be made to mix and mash for a comparison in cond below
 (setq rName (vlr-data rObj))
 ;NOTE!!!  the lispending or cancelled reactor doesn't give any data about which
   ;lisp is ending.
 (setq rCmd (car info))
 ;I'm using a list and wcmatch to match rCMD with a lisp function
 ;however you can direct compare since you mentioned loading certain vars
 ;when a lisps is running.
 ;
 (cond
   ((and
      (wcmatch rName HideLisp)
      (wcmatch rCmd LispWatch))
    (cd:hidelisp)
    );
 ;expand cond statments to test for other combinations etc.
   );
 );defun cd:rCD2LaySave

Posted

wishbonesr,

 

As a tip, note that only one VLR Reactor Object is required, since the three event names can be grouped together in the callback list:

(vlr-lisp-reactor "cdlispreactor"
  '(
       (:vlr-lispwillstart . cd:rcd2laysave)
       (:vlr-lispended     . cd:rcd2laysave)
       (:vlr-lispcancelled . cd:rcd2laysave)
   )
)

To detect which event triggered evaluation of the callback function (as opposed to querying the reactor data in your example), you can use the vlr-current-reaction-name function from within the reactor callback function.

 

To discover the data passed to the callback function when evaluated, look into using the vlr-trace-reaction function as a good reactor debugging tool.

Posted

Thanks guys, all this is good information and as always I'm very grateful. You know I guess I'm forgetting about our good friend, the temporary text file. So much of this automation I've been doing not only in LISP but in VB.NET and now they want some more stuff in C#....in those apps I rely heavily on temporary text files to pass information from one program to the other. And now they have hired a web developer to try an webonize most of what myself and the other developers around here are doing. I can sure give this place kudos for not sitting on their laurels and doing things the same old way. Lots of new changes happening here.

Posted
As a tip...

 

Thanks bro. Always appreciate your feedback.

 

Ricky

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...