APL+Santa Fe previewed at the APL2000 Conference
Vector 22:2, page 41
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 41
Introduction¶
APL+SantaFe has been presented in detail during the APL2000 2005 User Conference. Put in a few words, APL+SantaFe is a 100% .Net version of APL+. Here are its main characteristics:
- it is a completely new APL written for .Net
- it is a pure .Net language (as VB.Net and C#)
- highly compatible with APL+Win, but about 5 times faster and as fast as C#
- with a few changes to iron the weaknesses of APL
- with a LOT of extensions and improvements, new tools & new options
- usable from within Visual Studio 2005 with intellisense, VS debugger, & everything available under Visual Studio 2005
- with still our so valuable Interactive APL Session
- with full access to Windows Forms and all .Net controls
- with syntax extensions to allow copy/pasting C# code and making it run with minimal changes
- with access to the whole .Net Framework 2.0
- with multi-processor, multi-thread, 64-bit processor & huge memory space support
- with common error handling like C# and VB.Net
- producing 100% managed code
- producing APL .EXE and .DLL files which can be consumed by other .Net languages
- allowing you to do real Object Oriented programs (support for: namespaces, classes, methods, properties, events, inheritance, polymorphism)
- many more enhancements
This article is a mixture of information taken from slides presented by APL2000 at the Conference and from notes I have written down while looking at the APL+SantaFe demos.
APL+SantaFe FAQ¶
-
What are the requirements to install APL+SantaFe?
You need the .Net Framework 2.0
In addition it is highly recommended to install and use Visual Studio 2005 -
What really is APL+SantaFe? Is it APL?
Yes -
Is it the old APL Interpreter?
No, it is a complete rewrite, but very similar -
Is it faster than APL+Win?
Yes, about 5 times faster! -
But, is it REALLY APL?
Yes, it is really APL, from top to bottom.
It is APL for .Net, a pure .Net language
There are no compromises, no tricks, just real APL for .Net
As fast as C# and C++ for .Net -
Is C# or VB.Net involved?
Is this a Translator? No
Is VB.Net involved? No
Is C# code generated? No
APL+SantaFe is just a new .Net language, 100% .Net -
What do I use? What do I create?
You create an APL .EXE or an APL .DLL. Porprietary workspaces no longer exists.
Your APL programs, classes, etc. are stored in one or more .apl text files -
Does it work with Microsoft Visual Studio?
Yes, it is entirely integrated to Visual Studio, just like C# or VB.Net -
Is there still an APL Interactive Session?
Yes, you can run APL Code in an Interactive Session, just like always -
Can I use other .Net DLL's and EXE's?
Yes, you can use any .Net DLL or .EXE in APL+SantaFe -
Can other .Net language DLL's and EXE's use the DLL's and EXE's I produce with APL+SantaFe?
Yes any other language can use the DLL's or EXE's I create with APL+SantaFe -
How about the APL font?
APL+SantaFe comes with a new Unicode APL font. But any Unicode font which includes APL characters would work. APL+SantaFe uses the MS Standard for alternate keyboards: this means the right Alt key (AltGr) creates APL characters and the left Alt key accesses menus
What are the differences with APL+Win?¶
The function header is treated differently: variables declared in the function header are global instead of local!
All variables used in the function are local by default!
Example:
The APL = primitive has been replaced by an “approximately equal” primitive noted ≈ .
The reason is that with floating point numbers expressions like: 1.1 - 0.1 are not strictly equal to 1 but only “approximately equal” to 1 and that APL+SantaFe needed the = symbol to represent assignment.
Example:
⎕wi is about 98% compatible with APL+Win ⎕wi
But ⎕wi now uses Windows Forms and is therefore 100% .Net managed code.
Example:
⎕wself←'fm' ⎕wi 'Create' 'Form'
⎕wself←⎕wi '.ed.Create' 'Edit'
⎕wself←'fm.lv' ⎕wi 'Create' 'Listview'
⎕wself←'fm.bn' ⎕wi 'Create' 'Button'
⎕wi 'onClick' 'function'
Existing ⎕wi required you to wait for new controls
Existing ⎕wi did not reveal all methods, properties and events
Existing ⎕wi provides methods, properties and events specific to APL
New ⎕wi exposes all new controls, methods, properties and events
New ⎕wi takes text strings to create object
New ⎕wi can take XAML to create objects
APL+SantaFe Enhancements¶
Access to all of Windows Forms and .Net Controls¶
APL+SantaFe can use the Visual Studio User Interface WYSIWYG designer to create forms
APL+SantaFe can use Data Binding (to connect controls to databases)
With APL+SantaFe you have access to:
- Controls
- Themed Controls
- User Defined Controls
- Gradients
- FlowPanels
- TablePanels
- Transparencies
- All objects available to a C# or VB.Net programmer
Enhanced operators¶
All APL operators have been included in APL+SantaFe but some have been enhanced.
Example:
Complex numbers have been added to be compatible with APL2
New ⎕ucs System Function¶
A new system function has been added to return the Unicode index of APL characters (and vice versa)
Example:
Users can still use APL exactly as today, but they can also use new ways of doing things.
Two ways for defining APL functions¶
Note: in the following, a lot of the enhancements have been added to allow you to copy/paste C# code examples you may find in Google and have them run in APL+SantaFe with the least possible changes. However one can still limit himself to using only traditional APL constructs and not use these enhancements if he does not want to.
For example, they can define APL functions in 2 different ways:
namespace Demo1{
public class Class1{
public ƒ Class1(){
// Default constructor
r←"Hello World"
c←10 ADD 20
c1←nADD(10,20)
}
∇ r←a ADD b
r←a+b
∇
public ƒ r←nADD(a,b){
r←a+b
}
}
}
In this example, a function ADD is defined in the usual APL way, while a function nADD is defined using the new C#-like notation.
Note the ƒ symbol which is required when using the new C#-like notation. Note also the way arguments are defined in the nADD function and how the nADD function is called in the Class1 default constructor. This new notation allows for passing more than 2 arguments to APL functions.
You must use the new C#-like notation if you want other .Net programs to be able to consume your APL+SantaFe programs.
New ⎕monadic and ⎕dyadic system functions¶
Two new System Functions have been added to simplify testing for the presence of a left function argument:
:if 0≈⎕nc'a' ⋄ ... ⋄ :endif // time consuming
:if ⎕monadic ⋄ ... ⋄ :endif // much faster
:if~⎕dyadic ⋄ ... ⋄ :endif // also available
The return keyword¶
The new return keyword has been added to return values from functions:
return 99 // may return a constant
return b // may return an variable
return 10+b // may return any APL expression
Support for default argument values¶
When passing arguments to functions, it is now possible to use default argument values:
The nAdd function may now be called with only 2 arguments: it will be as if 3 arguments will have been passed with the 3rd argument equal to 100.
Function overloads are supported¶
You may define as many functions with the same name as you want, as long as they vary by the number of their arguments:
Printed pages 47–50 are missing from the only scan of this issue.
a ← @'c:\program files\' + @'apl2000\text.txt'
// don't want to use escape characters
a
c:\program files\apl2000\text.txt
Types¶
- APL+SantaFe supports ALL .Net types
- In addition APL+SantaFe supports true booleans (1 bit per element) while other languages like C# treat booleans as integers
- In APL+SantaFe every string is used as Unicode
Control Structures¶
You can still use all the APL+Win traditional control structures. Remind yourself that the = primitive has been replaced by the "approximately equal" primitive: ≈
However, you can also use all of the C# control structures (which will make it much easier to copy/paste C# code into your APL programs). Here are a few examples:
if (a ≈ 1) {
...
} else if (a ≈ 2) {
...
} else {
...
}
i = 0
while (i<a) {
...
i++ // added to APL so that we can copy/paste code from C#
} else { // in case while does not run even once (extension)
...
}
foreach i in ⍳5 {
...
}
:for i :in ⍳5
...
:endfor
for(i=0; i<a; i++){ // the following also works!
...
} else { // extension: if the for block never
// executes, then else block executes
...
}
// instead of i++ we can use an APL expression
i = 0
do {
i++
} while (i<a)
Microsoft has Code examples everywhere in MSDN: most examples can be copy/pasted to APL+SantaFe with minimum code changes.
There even is a Paste Special feature which automatically translates * (times in C#/VB.Net) to × and / (divide in C#/VB.Net) to ÷
Logical 'or' and 'and'¶
You can use the or and and keywords in APL expressions:
a ← (b ≈ c) or c ≈ d // if b≈c is true then c≈d is not executed
a ← (b ≈ c) and c ≈ d // if b≈c is false then c≈d is not executed
Keywords¶
In order to allow APL+SantaFe to be able to use C#-like Control Structures and more, APL+SantaFe recognizes 28 or so keywords. However you can still use any of these keywords in your programs as variable or function names. As soon as you do that, you can no longer use the given word as an APL+SantaFe keyword any more in your program.
Try ... Catch ... Finally¶
C# and VB.Net use Try ... Catch ... Finally constructs to allow writing better and more secure code. The idea is: you Try a block of APL code: if any error occurs in the code, the Catch block is immediately executed and in any case the Finally block of code is always executed. Moreover, APL+SantaFe recognizes and can use ALL predefined .Net exceptions.
Here is an example:
try {
:select a
:case 1
⎕error'DOMAIN' // cover to throwing errors
:case 2
⎕error'LENGTH'
:case 3
⎕error'SYNTAX'
:case 4
⎕error'MYERROR'
:case 5
throw ApplicationException("SFERROR")
:endselect
b ← +/a
⎕ ← 'no error'
} catch ('DOMAIN') { // partial match if DOMAIN in error msg
⎕←'domain error caught'
} catch ('LENGTH') {
⎕←'length error caught'
} catch ('SYNTAX') {
⎕←'syntax error caught'
} catch (Exception err) {
⎕←err.Message
} catch {
⎕←'all other errors caught'
} finally {
⎕←'finally always runs'
}
Miscellaneous:
⎕def works in 2 ways: ⎕def'∇ ... ∇' or ⎕def'ƒ ...'
⎕def supports ⎕cr and ⎕vr arguments.
The execute APL primitive (⍎) works in APL+SantaFe as in APL+Win . It is 100 times faster (precisely 103 times faster) than dynamic functions in .Net. Execute now runs in the same domain. Execute works in the APL Session
⎕fmt extensions¶
- Supports all .Net format strings
- Includes support for DateTime format strings
- Support specifying column widths
- Supports format string for each element in a matrix
- Pattern formats supported
- Supports NumberFormatInfo for culture or program specific settings
⎕nfi - Culture specific number formatting.
nfi←⎕nfi
nfi.negativesign←'¯' // or: nfi.negativesign←'-'
// no need to reassign ⎕nfi
// nfi setting is automatically respected by ⎕fmt and ⍕
Consuming APL+SantaFe class from C# and reciprocally¶
A Solution can contain many projects. Each project may be in a different language (C#, APL+SantaFe, VB.Net, …)
Example: A Visual Studio 2005 Solution may contain:
- an APL Santa Fe project
- a C# Class Library
or vice versa.
Assume we have written an APL+SantaFe DLL containing a Spread class in a namespace called utils and that our Visual Studio Project called WinSpread is written in C#.
In order to use the APL+SantaFe Spread class from C#, you need to:
add a Reference to utils in the WinSpread C# project (right click References / click Add / click the Browse tab and browse for the APL+SantaFe DLL file to add)
add a using clause:
Now here is how the C# class would for example use the APL Santa Fe Class:
utils.Spread sp = new utils.Spread(); // instantiate class
int[] total = new int[] {100, 200, 300};
int[,] matrix = new int[3,3] {{110,220,330},{110,220,330}, ... }
int[,] res = (int[,]) sp.SpreadTotal(total, matrix); // call the
Here is how you would have defined the SpreadTotal function in APL+SantaFe:
ROUNDCOL and SPREAD being private methods of the Spread class.
Note that, because we want C# to consume the SpreadTotal method we need to strong type the result by casting it to an (int).
The final compiled program is an EXE (or DLL): no one can tell if it was written in C#, VB.Net, Santa Fe, J#, C++ or a mixture of these languages!
Windows Forms¶
You can use 100% of Windows Forms and .Net controls in APL+SantaFe in addition to ⎕wi. Here is a short example:
myfm = Form()
mybt = Button()
myfm.Controls.Add(mybt)
mybt.Text = 'hello'
myfm.ShowDialog() // modal form
myfm.Show() // modeless form
Reminder: APL+SantaFe gives access to 100% of the .Net 2.0 Framework Classes, Methods, Properties!
Typed Arguments¶
- APL+SantaFe functions now supports typed arguments
- fn(int a, long b) will be seen as a typed call by other .Net language
- ƒlong fn(int a, string b) will return a long to other .Net languages
Conclusion¶
This was just a compilation of my notes taken on the fly at the APL2000 2005 User Conference. I hope you have enjoyed discovering this “soon to be released” completely new version of APL. More will be posted to my Web Site as new information is released and as soon as I can try the Beta version.