QUAD XLOAD

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

QUAD XLOAD

Postby ray on Sun Jun 14, 2015 12:12 pm

Dylaog APL supports ")LOAD" ")XLOAD" but not a "⎕XLOAD".


I have frequently wanted a ⎕XLOAD, say to examine a CONTINUE ws under program control, or initialise MiServer to run my own site without making a copy of the Dyalog supplied MiServer dws.

So here is what I have implemented (under Windows).

      fname Run_quadlx targetwsid;text;string;er;pt;bin;root;cl;clip_string;Str2Pf;specialkeys;key0;fname
⍝ ")Xload" wsid and execute the named function (copied from this workspace) in it
⍝ WARNING over-rides contents of PF key 0, and the clip-board
⍝ WARNING a function with the name defined in fname should not alreay exist in the target workspace.

er←'`ER`' ⍝ Define the "enter key"
pt←'`PT`' ⍝ Define the paste key (Reads the clipboard content)

:If 0=⎕NC fname ⍝ Check named function exists in this workspace
'Missing function "',fname,'"'
:Return
:End

Str2Pf←{ ⍝ Converts string with special keys ready for PFKey contents
d←'`' ⍝ delimiter used to define special keys
⍵≡'':'' ⍝ Empty string
~d∊⍵:⍵ ⍝ Simple string
⍝ We have a complex string with special keys
pre←(∧\d≠⍵)/⍵ ⍝ text before delimiter
post←(⌽∧\d≠⌽⍵)/⍵ ⍝ text after last delimiter
rest←(⍴pre)↓(¯1×⍴post)↓⍵ ⍝ text without pre and post
rest←⊃,/d specialkeys rest ⍝ deal with special keys in the rest
pre,rest,post ⍝ return text to put onto PFkey
}
specialkeys←{ ⍝ deal with delimited keyword such as the Enter key and the Paste key
⍝ ⍵ might be "`ER``PT``ER`"
∆←1↓¨(⍵=⍺)⊂⍵ ⍝ split into vector without delimiters
⍝ ∆ might then be
⍝┌→───────────────────────────┐
⍝│ ┌→─┐ ┌⊖┐ ┌→─┐ ┌⊖┐ ┌→─┐ ┌⊖┐ │
⍝│ │ER│ │ │ │PT│ │ │ │ER│ │ │ │
⍝│ └──┘ └─┘ └──┘ └─┘ └──┘ └─┘ │
⍝└∊───────────────────────────┘
bo←(⍴∆)⍴1 0 ⍝ compression boolean
⍝ bo would then be 1 0 1 0 1 0
⊂¨bo/∆ ⍝ enclose the special keys
⍝ what would be returned would then be
⍝┌→───────────────────────────┐
⍝│ ┌──────┐ ┌──────┐ ┌──────┐ │
⍝│ │ ┌→─┐ │ │ ┌→─┐ │ │ ┌→─┐ │ │
⍝│ │ │ER│ │ │ │PT│ │ │ │ER│ │ │
⍝│ │ └──┘ │ │ └──┘ │ │ └──┘ │ │
⍝│ └∊─────┘ └∊─────┘ └∊─────┘ │
⍝└∊───────────────────────────┘
}

⍝ build a string to put into PFkey 0
string←')xload ',targetwsid,er ⍝ Stack command to )XLOAD the target ws
string,←pt,er ⍝ Stack a paste command
key0←Str2Pf string ⍝ convert string into nested structure

⍝ Store key0 into PFkey 0
bin←key0 ⎕PFKEY 0 ⍝ Put "stacked commands" into PFkey ZERO

⍝ build a string to put into the clipboard
clip_string←'''',fname,'''⎕CY''',⎕WSID,'''' ⍝ Copy the named fuction from here
clip_string,←'⋄ ',fname ⍝ Execute the named function

⍝ Put clip_string into a clipboard object
'cl'⎕WC'Clipboard' ⍝ Create a Clipboard
'cl'⎕WS'Text'clip_string ⍝ put string on to the clipboard

⍝ Press the ZERO PFKEY "F0"
2 ⎕NQ'⎕se' 22 'F0' ⍝ Now Simulate KEY PRESS event


The right hand argument is the name of the (target) workspace to XLOAD.

The left hand argument (fname) should be the name of a function in the current workspace that you want to run in place of the ⎕LX in the target workspace.

Basically, puts the instructions to "copy the named function into the workspace and execute it" into the clipboard.

It also puts the instructions to ")XLOAD the target workspace and PASTE the clipboard content" into the PFKey 0.

It then simulates a keypress event on PFkey zero.

I hope someone else find this usefull, or can suggest a much simpler solution!
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: QUAD XLOAD

Postby MBaas on Mon Jun 15, 2015 5:09 am

I have a much simpler suggestion...at least to "initialise MiServer to run my own site without making a copy of the Dyalog supplied MiServer dws".
Load miserver.dws via command-link (or create a shortcut for it) and include parameter MiServer={NameOfSitetoStart}
User avatar
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: QUAD XLOAD

Postby ray on Mon Jun 15, 2015 1:21 pm

>Load miserver.dws via command-link (or create a shortcut for it) and include parameter MiServer={NameOfSitetoStart}

Thanks for that, very useful to know, but because my class has some :INCLUDES of (non scripted) workspaces, I need additional processing to avoid errors such as

line(1,13) : error AC0556: include target can only be a namespace " :Include #.hex_fns"

even if just running the MiServer.

When developing, I run a lot more at start up of MiServer.

But this technique can be used to do other tasks, such as implementing a STORE command.
(If ")Copy wsid fn" copies the fn into the active workspace from wsid on file
"]Store wsid fn" would copy the fn from the active workspace to wsid on file.)
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest