Page 1 of 1

Suggestion of a latent expression for workspace closure

Posted: Mon Jul 11, 2011 3:52 am
by michaelk
Much as latent expressions now are executed when a workspace is opened, I think it would be useful also to have latent-like expressions that are executed when a workspace is closed. One application of such a latent expression could be to expunge any printer object that happened to remain open when the workspace was closed.

Would anyone else find this proposed extension to Dyalog useful?

Re: Suggestion of a latent expression for workspace closure

Posted: Mon Jul 11, 2011 2:49 pm
by Dick Bowman
I think that this could/would be properly done by your application code. The point of ⎕LX being to force some application code to run when the interpreter has just started and has nothing to do - ⎕LX gives it that something. But once you've started, then you're in control.

Of course, I write this from a context of domineering applications. There might be a case where your workspace is just sitting there waiting for you to interact with it.

But personally, I don't think I've ever felt the need...

Re: Suggestion of a latent expression for workspace closure

Posted: Mon Jul 11, 2011 3:35 pm
by paulmansour
Isn't this better accomplished with a simple Off function that does what you want and then does a quadOFf at the end? ? As Dick notes, the reason for quadLX is that you want something to happen automatically. You have to take action as it is to close a session, so why not do Off instead of )Off.

Re: Suggestion of a latent expression for workspace closure

Posted: Mon Jul 11, 2011 11:13 pm
by michaelk
But there are numerous ways that a workspace can be closed other than by typing ')OFF'. They include loading another workspace, closing the session window, etc. My proposed latent-expression-at-workspace-closure would be invoked in all such circumstances.

Re: Suggestion of a latent expression for workspace closure

Posted: Tue Jul 12, 2011 1:13 pm
by Vince|Dyalog
Hi MichaelK,

Just to let you know, we do expunge your GUI objects such as printer objects when you )clear or load another workspace or Exit the interpreter.

JD has said to me that you can achieve some of what you are asking for with classes, event callbacks, and a destructor method.

Here is what I've come up with:

)cs ⎕SE

Start editing a new class:
)ed ○wsdestro

Paste the following into the editor and save it.

Code: Select all

:Class wsdestro

    ∇ closing
      :Implements Destructor
      'm'⎕WC'msgbox' 'Closing...'
      ⎕DQ'm'
     
    ∇
:EndClass


Add the following initialization function call to the WorkspaceLoaded event callback.
)ed ⎕SE.Dyalog.Callbacks.WSLoaded

⎕SE.wsclosingmsg←⎕NEW ⎕SE.wsdestro

Save the session file.

Regards,

Vince