Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler....

26
Spice Spice in Dyalog Document V1.06

Transcript of Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler....

Page 1: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

SpiceSpicein Dyalog

Document V1.06

Page 2: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Spice Utilities

Spice is a user command handler.

Under V11 & V12 it uses an input area at the bottom of the screen to issue user defined commands using SALT.

It can be initialized directly from SALT:

Page 3: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Initializing Spice

The Spice input area can also be started automatically by using the <enableSpice> function in the SALT workspace:

)LOAD SALT

enableSpice

Page 4: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Initializing the Spice area in V12The configuration menu:

Page 5: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Initializing Spice in V12.1There is no need to initialize the Spice input

area in 12.1.

The Spice user command handler is always available directly through the ] with 12.1.

Simply use ] where you would use the input area, e.g.

]mycmd

Page 6: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Spice HelpTo get a detailed list of all available

commands enter ]?+ or ‘?+’ in the input area:

?

+

+

Page 7: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Example of a custom Spice command: ffind

Use “ffind string” to find a regular expression string in SALT folders , e.g.:

]ffind \babc>0$

Will find in SALT files where syntactic abc is greater than 0 at the end of a line.

Page 8: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Using SALT commands in Spice

All the SALT commands but New can be issued here, e.g.:

]save myclass file1

]compare file1 -ver=4

]list mine

]settings

]load myfile

]removeversions filex -v=<9

Page 9: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

- Spice commands are kept in script files,

like SALT.

- Spice files have a .dyalog extension.

- All Spice script files are kept by default in

folder

[Dyalog]\SALT\spice

Page 10: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

Each script file contains a class or a

namespace with a number of

(presumably) related commands.

For example a script/class could contain

1. a command to search text

2. a command to replace text

Page 11: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

A script file MUST contain at least 3 public

shared functions for the Spice handler:

1. A <List> function

2. A <Run> function

3. A <Help> function

It may contain other functions.

Page 12: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <List> function

The <List> function is niladic.

It returns a list of as many namespaces as

there are commands in the script file.

E.g.: if there are 2 commands in the script

file it returns 2 namespaces.

Page 13: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <List> function

Each namespace returned by <List> contains

4 variables; each one is a string:

1. Name: the name of the command

2. Group: the group the command belongs to

3. Desc: a short description

4. Parse: the parsing rules

Page 14: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <List> function

The 4 variables:

1. Name: a single word, e.g. locate

2. Group: a single word, e.g. files

3. Desc: a sentence, e.g. Find string in files

4. Parse: a string describing the command

syntax, e.g. 2 –exclude=

Page 15: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <List> function (example with 2 cmds) ∇ r←List :Access Shared Public r←⎕NS¨2⍴⊂'' r.Name←'Locate' 'Replace' r.Group←⊂'Files' r.Parse←'1' '2' r[1].Desc←'Find a string in files' r[2].Desc←'Replace a string by another' ∇

Page 16: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <Help> function

The <Help> function is ambivalent.

Its arguments are a string naming the cmd

to return detailed help for, e.g. Locate to

the right and the help level to the left.

It returns a string describing help for that

command.

Page 17: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <Help> function (example with 2 cmds) ∇ r←level Help Cmd :Access Shared Public r←⊂'Shows where the string is found' r,←⊂'Replace a string by another' r←r⊃⍨'Locate' 'Replace'⍳⊂Command

→lev↓0 r,←⎕av[4],'More help here…'

Page 18: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <Run> function

The <Run> function is monadic.

It takes 2 arguments:

1. a string naming the command to deal

with, e.g. Locate

2. either a string or a namespace which is

the argument to the command

Page 19: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

How does Spice work?

The <Run> function (example with 2 cmds)

∇ r←Run(Cmd ca);ct;w

:Access Shared Public

r←0 0⍴'' ⋄ ct←⎕SE.SALT.Load'Utils\fileUtils -noname'

w←##.textUtils.splitOn⍨⎕SE.SALT.Settings'workdir'

:Select Cmd

:Case ‘Locate’ ⋄ w ct.showExpr¨⊂ca.Argument

:Case ‘Replace’ ⋄ w ct.replExpr¨⊂ca.Argument

:EndSelect

Page 20: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Example

See script Spice\aSample.dyalog

It contains 2 examples of Spice commands:

1. no parsing rules

2. with specific parsing rules

Page 21: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Example

The syntax is described in the help:

Page 22: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Example

If the syntax is wrong Spice will complain:

No arguments!

Page 23: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Example

If the syntax is right Spice will do it:

Page 24: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Spice command location

When APL is installed the Spice commands' location is [Dyalog]\SALT\spice but you can change it.

The SALT settings contain Spice’s commands location in cmddir:

]setting cmddir \my\own\user\cmds

Will change the Spice/user commands folder to \my\own\user\cmds

Page 25: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Final

SPICE is a development tool.

It can be used to store frequently used (and even less frequently used) user

commands.

Page 26: Spice Spice in Dyalog Document V1.06. Oct 2011 Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of.

Oct 2011

Short Final

More information can be found in the Spice document.

Dyalog 2009