20.11.2013 Views

APL-Journal - APL Germany e. V.

APL-Journal - APL Germany e. V.

APL-Journal - APL Germany e. V.

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>APL</strong>-<strong>Journal</strong><br />

Dyalog Version 11.0<br />

Morten Kromberg<br />

With the addition of classes and the ŒNEW system function<br />

for creating instances of classes, version 11.0 is the first version<br />

of Dyalog <strong>APL</strong> with core language support for writing<br />

object oriented applications. However, objects are not entirely<br />

new to Dyalog <strong>APL</strong> – the first objects appeared in the language<br />

around 1990.<br />

The first recognisable „objects“ were introduced into<br />

Dyalog <strong>APL</strong> when the Windows GUI interface was added in<br />

version 6.3 – in the early 1990’s. Apart from the word property<br />

to describe a „variable which was a child of a GUI object“,<br />

object terminology never really caught on in the <strong>APL</strong><br />

community – but whether we knew it or not, GUI elements<br />

like forms, labels or buttons were in fact classes that the <strong>APL</strong><br />

developer could create instances of, and these instances had<br />

properties and methods.<br />

The new objects were created and manipulated using a set<br />

of new system functions,ŒWC for the creation of objects,<br />

ŒWG and ŒWS for getting and setting the value of properties,<br />

and ŒNQ for triggering events and calling methods. The<br />

original syntax required the names of objects and their members<br />

to be given as strings. For example, the statement<br />

'MyForm' ŒWS 'Caption' 'Hello World'<br />

… would set the caption of MyForm. Over the next<br />

few years, Dyalog <strong>APL</strong> learned to recognize COM and<br />

Microsoft.Net classes and objects. Within <strong>APL</strong>, we were able<br />

to create namespaces, which were objects in that they contained<br />

collections of variables and functions. With namespaces came<br />

the familiar (to some) dot notation which <strong>APL</strong> shares with<br />

most other object-oriented languages, allowing the above<br />

expression to be shortened to:<br />

MyForm.Caption½'Hello World'<br />

… which is an obvious improvement in terms of readability.<br />

Finally, it was realized that references to objects could<br />

be stored in arrays, and the dot notation could be extended<br />

to allow nested name references, allowing expressions like:<br />

Btns½MyForm.(Button1 Button2 Button3)<br />

Btns.(Caption Posn)½<br />

Ç('Save' 'Cancel' 'Help'),[1.5] 100,¨ ¯40+50×ì 3<br />

Namespaces were different from other objects in that they<br />

were not based on a class definition: Each namespace was<br />

created empty and could be filled with anything the <strong>APL</strong><br />

developer desired. One could perhaps argue that this is „how<br />

<strong>APL</strong> objects should be“, but there are situations where a<br />

blueprint makes ideas clearer and solutions simpler. In particular,<br />

we often want to share the same code between several<br />

namespaces without actually having several copies of the<br />

source code.<br />

In addition to using objects within <strong>APL</strong>, the need for describing<br />

<strong>APL</strong> components in terms which are easily understood<br />

by users of other languages has become very important<br />

as standards like COM and .Net have made it practical<br />

to craft solutions from components written in more than<br />

one language. Although it has been possible to do this in<br />

Dyalog <strong>APL</strong> for several releases, it was clear that this could<br />

become more straight-forward if it were possible to define<br />

classes in <strong>APL</strong>.<br />

The main feature of version 11.0 of Dyalog <strong>APL</strong> is the<br />

introduction of classes as part of the <strong>APL</strong> language. Classes<br />

can be used to create instances. In a nutshell, a class definition<br />

defines the functions and variables which will be available<br />

from within each instance of the class. For example, the following<br />

class definition defines a class for which every instance<br />

will contain the variables Name and Price (and sets<br />

default values for them).<br />

:Class Product<br />

:Field Public Name½''<br />

:Field Public Price½0<br />

:EndClass<br />

This allows:<br />

<strong>APL</strong> - <strong>Journal</strong> 2006, 25. Jg., Heft 1/2 11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!