Using Dyalog APL as a scripting language

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Using Dyalog APL as a scripting language

Postby alexeyv on Fri Feb 03, 2017 7:41 pm

The GNU APL allows to write APL code in text file and execute it as an ordinary script:
Code: Select all
#!apl --script --

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝
⍝ Simple APL script example

a←⍳10
⎕←a

)off

Run it:
Code: Select all
./print.apl
1 2 3 4 5 6 7 8 9 10



Is there a way to use Dyalog APL in the similar manner?
alexeyv
 
Posts: 50
Joined: Tue Nov 17, 2015 4:18 pm

Re: Using Dyalog APL as a scripting language

Postby alexeyv on Thu Apr 06, 2017 7:00 am

Ok what I finally did was to create a workspace with
      ⎕LX←'⍎''main''⋄ ⎕off'

where main is the entry function, and run it like this:
Code: Select all
dyalog -b -s ~/Sources/apl/dyalog-workspaces/test.dws


However there are 2 problems here:
1. If I want to "load" this workspace again, it closes the interpreter (because ⎕LX contains ⎕off)
2. I couldn't find a way to send command line arguments to the workspace.

Is where a way to overcome these problems?
alexeyv
 
Posts: 50
Joined: Tue Nov 17, 2015 4:18 pm

Re: Using Dyalog APL as a scripting language

Postby woody on Thu Apr 06, 2017 2:12 pm

Maybe

⎕XLOAD WSNAME

or

)XLOAD WSNAME

?
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
User avatar
woody
 
Posts: 76
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA

Re: Using Dyalog APL as a scripting language

Postby alexeyv on Thu Apr 06, 2017 6:32 pm

Thanks, this solves problem 1.
alexeyv
 
Posts: 50
Joined: Tue Nov 17, 2015 4:18 pm

Re: Using Dyalog APL as a scripting language

Postby woody on Thu Apr 06, 2017 10:04 pm

I found this info from the late, great Dan.

You can pass a variety of arguments when calling APL... and then dig them out with

2 ⎕NQ'.' 'getcommandlineargs'

If you use 2 ⎕NQ'.' 'getcommandlineargs' you will get all the command line arguments as a VTV (Vector of Text Vectors) which you can deal with.

There are many arguments you can give to the interpreter - they are listed in the PDF in the help folder.

Those that are not recognized by the APL interpreter are left alone. You could use this feature to pass your own arguments, e.g. PORT=4500.

Hope that helps!

//W
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
User avatar
woody
 
Posts: 76
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA

Re: Using Dyalog APL as a scripting language

Postby jwied on Tue Apr 18, 2017 5:42 am

Instead of the latent expression, you could use a script-file "*.dyalog" with scripted APL commands - created with ]save - and pipe this into dyalog.exe:

dyalog.exe <commands.dyalog -x -q myworkspace.dws
jwied
 
Posts: 3
Joined: Wed Feb 24, 2010 7:30 am


Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest