User Commands in Dyalog APL By Dan Baronet A programmer's tool - V1.03.

Slides:



Advertisements
Similar presentations
Debugging ACL Scripts.
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
User Commands (UCMDs) in Dyalog APL A programmer's tool V1.04 Dan Baronet.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Algorithms Series of mathematical or variable manipulations Integer a,b,c a = 12 b = 22 c = a * b (what is c?) 12 * 22 = 264.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Spice Spice in Dyalog V1.03. Sep Spice Utilities Spice is a user command handler. Under V11 & V12 it uses an input area at the bottom of the screen.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Introduction to a Programming Environment
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
UNIX By Darcy Tatlock. 1. Successful Log Into Unix To actively manipulate your website you need to be logged in. Without being logged in you cannot enter.
Ogden Air Logistics Center. Purpose of Excel2FV Many agencies produce point lists of different data (target lists, force locations, etc.) in either Excel.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
28/08/2015SJF L31 F21SF Software Engineering Foundations ASSUMPTIONS AND TESTING Monica Farrow EM G30 Material available on Vision.
SALT and Version Control How to handle projects using version controlled SALT V1.06.
Introduction to Shell Script Programming
New User commands in Dyalog APL Dan Baronet 2013 *
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
General Programming Introduction to Computing Science and Programming I.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Input, Output, and Processing
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
VB – Debugging Tools Appendix D. Why do we need debugging? Every program has errors, and the process of finding these errors is debugging Types of errors.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Fundamental Programming: Fundamental Programming Introduction to C++
Utilities in Dyalog APL Dan Baronet Boston 2011 V1.00 0Dyalog’11 - BostonUtilities.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
SALT and Version Control How to handle projects using version controlled SALT V1.07.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
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.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
1 CS161 Introduction to Computer Science Topic #9.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Files Tutor: You will need ….
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
20081 Converting workspaces and using SALT & subversion to maintain them. V1.02.
File and Folder CLI Commands 12/24/ Agenda Overview of OS functions and the SHELL Internal v External Commands Command History Making & Modifying.
Oct SALT in Dyalog V1.17. Oct Introduction SALT is a Simple APL Library Toolkit It is a source code management system for Classes and script-based.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
Oct SALT in Dyalog Doc v1.18. Oct Introduction SALT is a Simple APL Library Toolkit It is a source code management system for objects with.
Version Control and SVN ECE 297. Why Do We Need Version Control?
Chapter – 8 Software Tools.
Programming Fundamentals Enumerations and Functions.
Introduction to C Programming
13-1 ANSYS, Inc. Proprietary © 2009 ANSYS, Inc. All rights reserved. April 28, 2009 Inventory # Chapter 13 Solver.out File and CCL Introduction to.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Spice Spice in Dyalog V1.02. Oct Spice Utilities Spice is a cover for SALT. It uses an input area at the bottom of the screen to issue user defined.
Chapter 13 Solver .out File and CCL
Introduction to C Topics Compilation Using the gcc Compiler
Data File Import / Export
Scripts & Functions Scripts and functions are contained in .m-files
What is Bash Shell Scripting?
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Creating your first C program
Introduction to javadoc
Chapter 1 c++ structure C++ Input / Output
IS 135 Business Programming
Presentation transcript:

User Commands in Dyalog APL By Dan Baronet A programmer's tool - V1.03

Procedure This tutorial is divided into 4 areas: -Why UCMDs and introduction -Dyalog's UCMDs -implementation of the UCMD framework -Your UCMDs: how to write them

Why The idea is to provide a mechanism for accessing tools anywhere by -separating utilities from the common workspace -make them available at any time

History The concept of user commands (UCMDs) is not new. APL/PC had them in the 90s. Some IPSharp users had them (through S-Tasks) Their implementation was different but the idea was the same

User Commands A user command (UCMD) is similar to a system command like )LOAD or )WSID. It is a call to an independent routine written by a user, not a routine provided by the system. System commands start with a ), e.g. )SAVE User commands start with a ], e.g. ]WSLOC

User Commands - syntax Like their system commands counterpart, user commands may take arguments, e.g. )WSID [newname] And ]FNSLIKE [pattern] Like system commands they are not case sensitive.

User Commands - syntax Unlike system commands, in the actual implementation, they can also take modifiers, e.g. ]FNSLIKE [Pattern] –format Modifiers are preceded by a specific character (here -) Modifiers ARE case sensitive.

User Commands - syntax This is Dyalog's implementation. In fact, UCMDs could take any format WE decide what is acceptable

User Commands Dyalog comes pre-packaged with a set of user commands divided into groups. Groups exist for SALT, workspace utilities, code utilities, user commands management, etc.

User Commands For example the command ]SAVE, which saves an OBJECT (not a workspace), takes up to 2 arguments, saving the object named in the 1 st argument to, if present, the location named in the 2 nd argument. Ex: ]save myfn \my\location\myfn To bring the object back use the command ]LOAD: ]load my\location\myfn

User Commands - Help General help can be obtained with ]?? The list of all commands can be obtained with ]? And ]?+ Specific help for a command can be obtained with ]?cmdx Or more detailed help, if any, with ]??cmdx Or ]?\path\to\file\containing\a\user\cmd

User Commands available Dyalog comes pre-packaged with some already defined UCMDs They are divided into some 7 groups: -SALT -Spice (UCMD) -Svn -Sysmon -Tools -Transfer -wsutils

Group SALT These are the same as their SALT functions: -Saveobject[tolocation] -Loadlocation -Comparefile1[file2] -Settings[type[value]] -Explore[folder|file] -List[folder] -Snaptolocation -Removeversionsfile

Group Spice These are commands used to manage the User commands system: -Uloadcommand -UdebugON|OFF -Uclean -Unew -Ureset -Uversion -Umonitor

Group svn This group contains commands to mimic SubVersion's commands: -svnci: commit changes -Svnco: check out -Svnadd/delete: add/delete new files -Svnstatus/resolve -Svndiff: show changes to a file -Svnimport/export -Svnupdate: bring in most recent changes

Group SysMon This group is used to monitor the system: -APLMON: used to monitor expressions by primitive, ex: ]aplmon {+/1= ⍵∨⍳⍵ }¨ ⍳ 1000 –file=\tmp\data )LOAD APLMON InitMon '\tmp\data.csv' -CPUtime: used to find CPU used for expressions, ex: ]cputime {+/1= ⍵∨⍳⍵ }¨ ⍳ Monitor: used to find lines consuming the most CPU

Group Transfer This group is used to move code in and out of ATF files with -in/out And move code in and out of "extended" files with code translation with -inx/outx

Groups Tools & WSutils These 2 groups contain various utilities e.g. to show a subset of names following a specific pattern or do function call analysis or search the workspace for strings of code/text: ]fnslike GUI* -date=> ]fncalls MainProgram -details -treeview ]wsloc \babc[ ∧ \w]← -pattern -recursive

UCMDs - implementation The code to run a UCMD is contained in a class or namespace in a SALT (text, Unicode)file. That file may be host to several UCMDs Command names are case insensitive, e.g. ‘find’ and ‘FIND’ call the same code Switches names are case sensitive UCMDs are grouped together, e.g. utilities can be grouped under the group ‘wsutils’ The class or namespace must contain at least 3 public functions: ‘List’, ‘Run’ and ‘Help’

UCMDs - implementation The ‘List’ function is used to gather basic info displayed when using ]?+ The ‘Help’ function is used to display more complete info when using ]?cmdx or ]??cmdx The ‘Run’ function is the one doing the work.

UCMDs - implementation The whole framework is based on 2 things: -SALT: used to read/write Unicode text files -Spice: used to implement the rules of UCMDs

UCMDs – an example Let’s assume we have a simple function we wish to call once in a while without having to copy/call/erase it each time: calendar 3 Mars S M T W T F S

UCMDs – an example We need to create a class with the 3 basic functions, the function: :Class dates ⎕ IO←1 ⋄ ⎕ ML←1 ∇ r←List :Access Shared Public r← ⎕ NS ⍬ ⍝ Name, group, short description and parsing rules r.Name← 'cal' r.Group←'dates' r.Desc← 'returns the calendar for a given month' r.Parse←'' ∇

UCMDs – an example The HELP function: ∇ r←Help dummy :Access Shared Public r←'Enter a month as argument' ∇

UCMDs – an example The RUN function: ∇ r←Run(a1 a2) :Access Shared Public 'calendar' ⎕ CY 'myutils' r←calendar ⍎ a2 ∇ :endclass

UCMDs – an example Because each class may contain more than one UCMD the HELP and RUN functions should really account for that.

UCMDs – an example HELP function for more than one command: ∇ r←Help Cmd :Access Shared Public :Select Cmd :Case 'cal' r← 'Enter a month as argument' :Case 'other' … :EndSelect ∇

UCMDs – an example The RUN function for more than one command: ∇ r←Run(Cmd Args) :Access Shared Public :Select Cmd :Case 'cal' 'calendar' ⎕ CY 'myutils' r←calendar ⍎ Arguments :Case 'other' … :EndSelect ∇

UCMDs – Parsing If automatic parsing of the arguments is desired the system will look at the line given as argument, split the tokens on spaces and put the resulting vector of text vectors in variable 'Arguments' in a namespace. That namespace will be given as the 2 nd argument to the function. To request parsing simply put in 'Parse' (in function ) the rules to follow, e.g. '3' to ensure 3 arguments. If no parsing is desired simply leave 'Parse' empty.

UCMDs – Parsing If we wish the system to check the number of arguments (here 1) for us we tell it in : ∇ r←List :Access Shared Public r← ⎕ NS¨1 ⍴⊂⍬ ⍝ Name, group, short description and parsing rules r.Name← ⊂ 'cal' r.Group← ⊂ 'dates' r.Desc← ⊂ 'returns the calendar for a given month' r.Parse← '1' ∇ In that case the 2 nd argument in will contain a namespace:

UCMDs – Parsing ∇ r←Run(Cmd a2) :Access Shared Public :Select Cmd :Case 'cal' 'calendar' ⎕ CY 'myutils' r←calendar ⍎ 1 ⊃ a2.Arguments :EndSelect ∇ Function can also/should be defined in the class.

UCMDs – an example ]cal 3 Mars S M T W T F S

UCMDs – an example If Parsing is enabled, entering the wrong number of arguments will be refused: ]cal Command Execution Failed: too few arguments ]cal 2 3 Command Execution Failed: too many arguments

UCMDs location The location of user commands is preset to Dyalog's folder SALT\Spice under APL's location, e.g. C:\program files\Dyalog\V121\SALT\Spice

UCMDs location The location of UCMDs is one of SALT's settings. To know what they are: []SE.SALT.Settings 'cmddir' Or, as a UCMD: ]settings cmddir

UCMDs location You can reset it too. It follows the same rule as SALT's workdir setting, i.e. it is a series of paths separated by semicolons, e.g. \my\own\path ; C:\program files\Dyalog\V121\SALT\Spice For example, to add "\my\own\path" to the existing path: (note the comma) ]settings cmddir,\my\own\path

UCMDs location You can set them manually or in Options/Configure…

UCMDs location

Some commands are always there: Spice's and SALT's Doing (note NO comma) ]settings cmddir \my\own\path Will keep Spice and SALT's commands even though they have not been specified.

UCMDs – Advanced Topics Debugging code ]udebug ON|OFF When debugging is OFF errors are reported in the calling environment: Command Execution Failed: DOMAIN ERROR When debugging is ON errors are reported in the class: DOMAIN ERROR calendar[4] r←n÷month ∧

UCMDs – Advanced Topics Switches Those can be specified in the Parse variable: They come in different forms: -Without a value: /sw -With a value: /sw= -Maybe with a value: /sw[=] The specification for each includes the switch delimiter (here /)

UCMDs – Advanced Topics Switches A set of possible values may be specified, e.g. /animal=cat monkey giraffe A set of possible characters can also be specified: /vowel ∊ aeiou Or /vowel [ ∊ ] aeiou If the switch can be specified without a value

UCMDs – Advanced Topics Switches – Examples 1. Switch time takes a value, switch PM does not, switch delimiter is /: Parse ← '/time= /PM' 2. Switch Prime may accept values 2, 3, 5 and 7, switch Octal accepts values made out of ' ', delimiter is +: Parse ←'+Prime[=] Octal ∊ '

UCMDs – Advanced Topics Switches – Examples Switches and number of arguments are specified together. A command accepting 2 arguments and a switch offset with a value would be specified as: Parse ←'2 -offset='

UCMDs – Advanced Topics Arguments Arguments are delimited by spaces. If an argument must contain spaces, or the switch delimiter character or a quote, it should be surrounded by quotes. For example, if the switch delimiter is /, the following call will contain 4 arguments: ]mycmd 'arg 1' '2001/4/5' OK "I'm" /lights=on

UCMDs – Advanced Topics Long Arguments If a command accepts N arguments and the last argument may contain spaces then it may be unnecessary to quote the last argument simply by stating the command as "long". For ex, if command addrec accepts 3 arguments it could accept ]addrec Joe Blow 42 main str With Parse ←'3L' The arguments will be 'Joe' 'Blow' '42 main str'

UCMDs – Advanced Topics Short Arguments If a command accepts a maximum of N arguments it can be specified as "short". For ex, With Parse ←'3S' Any number of argument less than or equal to 3 will be accepted.

UCMDs – Exercices 1.Write a UCMD to display the time, formatted 2.Write a UCMD to display the time in another city

]END