Skip to content

Hacker’s Corner: Using Watchpoints in APL+Win 3.6

Vector 16:4, page 95

The text of this article is not yet online. No complete scan of this issue has been found. The only copy found, on vector.org.uk, is damaged: its page images are lost, but the text machine-read from them survives, shown below (help find a scan).

Unedited OCR text, machine-read from a scan now lost: it contains errors, and its APL is wrong. Shown for searching.

VECTOR Vol.16 No.4

Hacker’s Corner: Using and Abusing

Watchpoints in APL+Win 3.6

some experiments by Adrian Smith

Background Those of you who build applications in Causeway (shareware will know that its main design objective was to take away from the programmer (me) the responsibility of remembering which Gui objects needed to be updated when some underlying data changed. Now I think it is fair to have the programmer state explicitly the dependencies (“this field will need fixing when any following change ...”) although the screen design software can usually make a fair guess just by stripping the valid names out of the object’s data expression; what is not fair is to have to remember to notify  the change to some variable when you run a callback that re-assigns it. Surely the interpreter knows that you assigned some new data to user_name can’t it just tell the program?

Where do Watchpoints come into it? The concept of watchpoints has been around in real  development environments for years, and several old mainframe APLs (Xerox, Burroughs?) had something similar. Dyalog actually demonstrated ) watch in an early version of Dyalog/386 at a BAA meeting (to general acclaim) but somehow it never made it Windows interpreter. J has a related idea in the 4!:5 conjunction which reports all the names which changed since you last called it. For debugging, watchpoints are just amazingly useful. For example in my Rain graphics engine, I build the description of the chart as a simple character vector of PostScript code. This involves a lot of APL like ...

R+R,‘C ',(CHSFMT XPOS,TLF,XPOS,YL),' ] ',ATT,' ps pL ',nl

... to draw a polyline (1 think this may be a Y-axis). Quite often, my fingers get ahead of my brain and I forget to format the co-ordinates. APL is horribly tolerant of this kind of misdemeanour, so everything carries on until I hit WS FULL (because I now have some horrid nested heterogeneous miscegenation lurking in my workspace) or until I try to view the chart, save it to file etc.

95

VECTOR Vol.16 No.4

Now at the end of each block of code, the temporary variable R gets catenated toa global buffer with an expression like:

CHAPG+CHAPG, ps

.. Just suppose we could watch  this buffer and pull up short the moment it ceased to be a pure character vector? Well now we can, and it is amazingly easy to set it up:

Qwatchpoints+1 2p'CHAPG' ~a/CHaPGelav' chPlot 112 WATCH POINT TRIGGERED ~a/CHaPGeDav A si DwArcHPOrINT[i} CHacatle] chPlot{22]

So what happened, and where am I? Every time 1 make an assignment to the buffer, the expression ~,/CHAPGe(av is evaluated. If it is true (non-zero) then my code is immediately suspended in a phantom function called QWATCHPOINT, and I can look at the stack to see which line of my code caused the problem. Note that the help misleading here - it states The first column holds the name of the variable whose imminent change in value will trigger evaluation of the expression in the second colunin; ...” which implies that the suspension will occur before the damage is done. In fact it does the assignment first, but at least you have the smoking gun to hand.

Now, you can call functions in that right-hand column (whinge #2 ~ the help file states If the function returns a zero or no result, execution will not be suspended, but whatever code the function contains will have been executed.” but in fact you must return a result) and you can run as many expressions as you like against the same variable ...

Qwatchpoints+3 zp'x' 'QO+''x has changed'' x! X*12 x has changed 12 X has changed 12 x has changed 12

... but you can abuse it with things like ....

Owatchpoints+i 2p'x' 'Ok''x has changed'' (x+x+i)?

96

VECTOR VoL16 No.4

While we are in the mood, whinge#3 - the help file is quite explicitly wrong in stating Note also that the single character variable name Z must be raveled to a vector before assignment; scalars are not accepted.” - scalars are accepted, the example on the previous page.

This all begins to feel rather useful, not just as a debugging tool but quite possibly of a real application. Suppose we are running a +Win OLE server using Excel as the Gui interface. Maybe this is running some fancy statistical model, and it might maintain some intermediate variables to show how it is getting on. Perhaps the spreadsheet could display these variables as they change? Now all we have to do is to watch  the variables in our server and use the Notify method on root to tell Excel that something changed, and probably what it is and the new value. Which brings me to...

A 1-Line Causeway Engine

Remember, Causeway is all about things changing, and other things getting told about it. Suppose we have:

Aname Adrian Smith

v Flip Ca] a The famous Causeway 'Flipper' using watchpoints C2] fm' OWI 'Create! 'Form' (‘where' 24 12 12 40) C3] fm.ed' OWI Create  'Edit' (‘where! 2 4 1.2 24) C4] fm.ed' Qwi 'text' aname Cs] fm. bb' OWI Create  Button' ('caption' 8FPlip')({'where' 6 4 2 12) (6) fm. bb' Qwi 'onClick' aname«¢aname' (7) C8] Owatchpoints+1 2p'aname' '''fm.ed'' Dwi ''text'' aname' Ca] [10] 'fm' OWL Waitt v

Then Bob, as they say, is your uncle. Whether this is sensible, and if so how eae 2,] one might set about implementing it i see for real, remain open questions. . = However it works so simply and reliably I can’t help feeling that it has to be a technology worth exploiting. Watch this space!

97

Umbilic Torus NC by Helaman Ferguson, 1986 Umbilic Torus created in Jsoftware

Por those who see the elegance in an algorithm, Jsoftware offers an

OLAP programming language ideal for solving complex problems.

JSsoftware 1s the modeling tool of chotce

tn the art of programming.

Jsoftware is an OLAP language. It’s highly optimized for operating on whole high performance interactive nature datasets at a time, allowing you to allows a programmer to concisely manipulate data far more easily than express algorithms when analyzing with conventional software. Also,sparse amay support provides an efficient form of storage for very large data sets. complex data sets.

The core language is based on a small simple yet consistent rules with many powerful factlities to define new operations. Built-in functions a Make sure to join the JForum for a lively discussion on a variety of interesting J topics, ee: www, jsoftware.com/f « Strand Software, J foram. htm 19235 Covington Ct. Shorewood,MN 55331 (612) 470-7345 i Fax (612) 470-9202 aaa software.com info@jsoftware.com :