A Tale of Three GUIs

Dick Bowman

The major APL products running under Microsoft Windows all offer facilities for constructing 'conventional' Windows dialogs; but they are very different from one another and also vary in the way in which their facilities are documented.   It seemed interesting to construct the same (very small) application using various products and to compare the resulting code.

The APL versions are not the most current representatives of any of the vendor products; this article should not be construed as a serious critique of any of the products, although the general flavour of the code is unlikely to be greatly different in current products.

[A note about fonts: This article contains APL code and requires both the Dyalog APL and APL2 fonts to be available for proper display.]

Application:

A function to display a multi-line prompting dialog; with prefilled responses which the user can amend.  The dialog is closed using either the Cancel button or the Ok button.

Typically the function would be used with a syntax like:

    'Enter Name' Prompter ('First name' 'Elsie') ('Surname' 'Gribble')

If the user left the prefilled responses alone and closed the dialog with the Ok button the result would be

    1 'Elsie' 'Gribble'

Products used:

Dyalog APL Version7

APL2 Beta 7

J Release 3

Conclusions:

Dyalog APL Version 7

Although Dyalog offers an interactive form building tool my preference has long been to enter the code directly into a function; this is tedious (although copying from existing forms makes it less of a chore) but does bring the advantage of flexibility.

Code for the Prompter function:

 zcaption Prompter prompts;IO;ML;form;i
Multiline prompting dialog
IO ML1 3
formWCformcaption(coord pixel)(size(200,50+30prompts))
i0
Next:((ii+1)>prompts) End
(form.lab,i)WClabel(i 1prompts)(posn(10,15+i30))(size 20 75)
(form.edit,i)WCedit(i 2prompts)(posn(90,15+i30))(size 25 100)
Next
End:
form.okWCbutton OK(posn(10,20+30prompts))(size 25 50)(event select ߨOk)
form.cancelWCbutton Cancel(posn(70,20+30prompts))(size 25 50)(event select ߨCancel)
DQform
0
Ok:z1
i0
Nextline:((ii+1)>prompts) Endprompter
z,((form.edit,i)WGtext)~
Nextline
Endprompter:0
Cancel:z0,(prompts)

What's particularly advantageous here is that a single function can be used throughout an application no matter how many prompting lines are required; this is a versatile building block.  The code would be more aesthetically pleasing if written using the structured keywords of Version 8.  To keep things entirely neat and tidy I have included the callback processing inside the single function rather than split it out into separate functions.

Return to top

APL2 Beta 7

APL2 not only offers a form-building tool; its use appears to be compulsory.  It's well integrated with the development environment (double-click on a form definition variable and it opens automatically) and yet separate (no chance of any conflict with your own code).  But what it stops you from doing is creating the single multi-purpose function which is possible in both Dyalog and J.  Given a form which contains two labels and edit boxes the code looks like this...


za Prompter w;SV145;dialog;events;edit1;edit2;ok;label1;label2;cancel;close;�IO
Display and accept input from a two-box prompting dialogue
�IO1
dialogCREATEDLG a
'events' SHAREWINDOW dialog 'close'
'events' SHAREWINDOW dialog 'ok' 1
'events' SHAREWINDOW dialog 'cancel' 2
SHAREWINDOW dialog 'label1' 102
SHAREWINDOW dialog 'edit1' 101
SHAREWINDOW dialog 'label2' 103
SHAREWINDOW dialog 'edit2' 104
ok1 2'Command' 'zPromptOk 0'
cancel1 2'Command' 'zPromptCancel 0'
label11 1w
edit11 2w
label22 1w
edit22 2w
close('Close' '0')('Quit' '0')
DEFAULTPROC EXECUTEDLG dialog
DESTROYDLG dialog

zPromptOk
Respond to OK button
z1 edit1 edit2

zPromptCancel
Respond to Cancel button
z0 '' ''

The calling syntax is slightly different; with the name of the form object used as the left argument.  IBM's documentation of the GUI tools seems very poor (the supplied examples do not tie in well with the description) and it took quite some time to create this example; the code could probably be tidied up so that it looked more comparable to the other two examples.  In this case I have broken the callback processing out into separate functions, although it would probably be better for an example as simple as this to have included it inline.

Note the slight clumsiness in the way that controls are referred to by number (assigned by the form-building tool) rather than by name; this could easily be coded round and may just be an artifact of my incomplete understanding of how the APL2 facilities are supposed to operate.

Return to top

J Release 3

The J form building tool seems less invasive than Dyalog's (I think that while it is an impressive demonstration of Dyalog APL for the form builder to be written in APL it might have been better kept as a 'magic box'), but again there are benefits to bringing the form definition into the domain of native code.  Once again, it is relatively easy to create a single verb which can handle any number of prompting lines.

Prompter=: 3 : 0
NB. Multiline prompter
wd 'pc prompter closeok;'
for_j. i. $y. do.
ypos=.10+30 * j_index
wd 'xywh 8 ',(":ypos),' 40 14;cc label',(":j_index),' static;'
wd 'set label',(":j_index),' ',>0{>j_index{y.
wd 'xywh 60 ',(":ypos),' 95 14;cc edit',(":j_index),' edit ws_border es_autohscroll;'
wd 'set edit',(":j_index),' ',>1{>j_index{y.
end.
wd 'xywh 14 ',(":10+30*$y.),' 34 12;cc ok button;cn "OK";'
wd 'xywh 60 ',(":10+30*$y.),' 34 12;cc cancel button;cn "Cancel";'
wd 'pas 6 6;pcenter;'
wd 'pshow;'
wd 'wait;'
res=.wd 'q'
event=. ((0{"1 res)i.<'sysevent'){1{"1 res
select. event
case. <'prompter_ok_button' do.
z=.''
for_j. i. $y. do.
z=.z,1{((0{"1 res)i. <'edit',":j_index){res
end.
z=. 1;z
case. <'prompter_cancel_button' do.
z=. 0;($y.)$<''
end.
wd 'pclose;'
z
)

Notice here the improved readability which has come from the control words available in J.  Where J has lost out is that I couldn't find out how  to have a multi-word caption for the form; J appears (and I may well be wrong on this) to combine the form name and caption; this is fairly typical of the J GUI; within the bounds of its design it can be excellent, but the design itself is (quite deliberately, it appears) a simplification of the total Windows GUI.

The J form builder is more suited to non-modal dialogue than the modal example here.

Return to top

Conclusions

Dyalog APL offers the most versatile GUI facilities; there are lots of objects, which each have bountiful properties, events and methods; Release 8 is even more versatile than Release 7.  I tend not to use the form-building utility provided as part of Dyalog APL, but this is probably more a case of habit than anything.  If Dyalog suffers from anything it is probably a tendency for the vendor to include everything under the sun inside the product (good for versatility, not always good for consistency).

J offers a more restrictive set of GUI facilities; I tend to use its form builder more - at least to get a first cut of the form-building code.  I find J harder to work with than APL - probably because I do not work with it enough to have tailored the environment to suit my preferences.  The underlying language base is probably more consistent than any of the APLs.

APL2 is (regrettably) idiosyncratic in its approach; this wasn't helped by some GUI features (for example, menus) appearing not to work in the beta.  The documentation is noticeably poor (but again, this was the beta).  The available controls are fewer than with either Dyalog APL or J.  While it is clearly possible to create GUI-style application interfaces with APL2 there does not appear to be very much richness in the environment.  This is a disappointing product.

Return to top


Copyright Dick Bowman 1998-2013; latest update 13 March 2013 (repaired links)

Back to the J\APL Contents Page