Control structures in APL*Plus III

Abstract

Mention control structures to an APLer and you'll get one of two responses: "It's about time" or "What 's wrong with branch?" I have to admi t t h a t t h e r e w a s a t ime w h e n I was in the l a t t e r s choo l m y s e l f b u t as I spen t more t ime u s ing o the r p r o g r a m m i n g l a n g u a g e s (and ge t t i ng e x a s p e r a t e d a b o u t h o w h a r d t h e y made s imple th ings) I c a m e to a p p r e c i a t e the b e n e f i t t h e y could b r ing to APL. D u r i n g the l a s t two y e a r s , I got the c h a n c e to see t w o qui te d i f fe ren t a p p r o a c h e s to adding cont ro l s t r u c t u r e s to A P L f i r s t a ve ry APL-ish a p p r o a c h c o u r t e s y o f Rob Wil lhof t o f IBM, and t h e n Bill R u t i s e r ' s m o r e ADAi sh ve r s i on t ha t ha s now b e c o m e p a r t o f M a n u g i s t i c s ' A P L l k P L U S I I I for Windows . I w a s a t f i r s t v e r y t a k e n w i t h Rob ' s a p p r o a c h , b u t once I got m y hands on a p ro to type o f t h e A P L ~ P L U S vers ion , I found t rue happ iness . So w h y w o u l d an A P L e r w a n t con t ro l s t ruct u r e s ? Aider all, y o u r e a l l y can e m u l a t e all the t rad i t i ona l c o n s t r u c t s w i th b r a n c h a r row, a couple o f labels , a few a r r a y p r i m i t i v e s and m a y b e the occas i ona l execu t e . A w e l l k n o w n t e a c h e r o f A P L was h e a r d to s a y he w o u l d n ' t t e a c h control s t r u c t u r e s as t h e y wou ld d i s c o u r a g e s t u d e n t s f rom u s i n g a r r a y coz ts t ruc ts ! Well , t h e r e a r e two r ea s ons for adopting t h e m , one fa l l ing u n d e r " i m p l e m e n t a t i o n d e t a i l s " and t h e o t h e r f a l l ing s qua re l y u n d e r "prog r a m m i n g e r g o n o m i c s " or " h u m a n fac tors . " T h e f i r s t r e a s o n has to do wi th the w a y interp r e t e r s w o r k . W h e n y o u say X ÷ 0 , A P L adds a s y m b o l to the s y m b o l cab le and a l loca t e s m e m o r y for a b o o l e a n va lue . W h e n y o u f i rs t s ay X ÷ X + I , t he s y m b o l p o i n t e r ge t s c h a n g e d t 9 po in t to a n o t h e r l o c a t i o n w h e r e t h e r e s u l t o f the addi t ion goes. N e x t t i m e y o u do the X + X + I , A P L has to c o n v e r t the b o o l e a n a r g u m e n t s to i n t ege r s so t h a t i t can deal w i t h a 2 as wel l as do ing the m e m o r y allocation and symbol table redirection. You're also comparing the result to your limit variable each time round the loop. A lot of work is getting done to manage a simple loop counter. On the other hand, when you say :for X : in 150, APL can stick X into a register and do just a couple of machine instrudtions to manage the loop. Hey, presto, your code runs a lot faster. The second reason is much more important. Hauing control structures in the language lets you separate the data from the structure. There is a mas s ive c o n c e p t u a l d i f fe rence b e t w e e n , for e x a m p l e , c o m p r e s s i n g b l a n k r o w s f r o m a t e x t m a t r i x (a d a t a m a n i p u l a t i o n ) and dec id ing w h e t h e r to c r e a t e a file or t ie i t (a con t ro l ac t ion) . N o n a r r a y l a n g u a g e s a r e u n a b l e to do d a t a m a n i p u l a t i o n s on the sca l e o f APL. T h e y w o u l d be forced to t r e a t the d a t a m a n i p u l a t i o n a b o v e as a s e t o f con t ro l ac t ions , loop ing t h r o u g h t h e r o w s o f t he m a t r i x and k e e p i n g or t h r o w i n g a w a y e a c h one as a s e p a r a t e decision_ A P L e r s h a v e a h v a y s l o o k e d down upon s u c h l imi t ed l a n g u a g e s . A t the s ame t ime , u se r s o f t h o s e a r r a y c h a l l enged l a n g u a g e s h a v e s n i c k e r e d a b o u t A P L e r s h a v i n g to use da ta m a n i p u l a t i o n s to i m i t a t e c o n t r o l ac t ions . W h e n y o u t h i n k a b o u t it, "branch to the result of using a test result to optionally compress a data variable containing a relative code address (or label, aa we call it)" is no t v e r y log ica l . I f y o u ' r e no t conv inced , F i g u r e 1 on p a g e 21 s h o w s some typ ica l b i t s o f code, done f i r s t in t rad i t iona l A P L and t h e n as t hey w o u l d be m a n a g e d in A P L ~ r P L U S III . In some cases, t h e s t r u c t u r e d code is a l i t t l e longer , in o the r s a l i t t l e s h o r t e r . In al l t he cases , howeve r , i t is a b u n d a n t l y c l e a r w h a t the code is t r y i n g to do, even to a nov i ce A P L e r . W h a t m a y be m o r e i m p o r t a n t to t h e f u t u r e o f A P L as a p r o g r a m m i n g l a n g u a g e is t h a t i t wi l l a p p e a r to m a k e s e n s e to a m a n a g e r w h o d o e s n ' t p r o g r a m in any ' th ing b u t w a n t s his p e o p l e to u se a l a n g u a g e he t h i n k s he wou ld u n d e r s t a n d i f he put his mind to it. U n f o r t u n a t e l y , i t is, f a r too ofl:en, peop le f r o m th is l a s t g roup w h o ho ld o u r l ives in t h e ba l ance . E v e n w i t h o u t the po l i t i ca l b e n e f i t s , c o n t r o l s t r u c t u r e s b r ing s e v e r a l b e n e f i t s to A P L . O n e is t h e ab i l i ty to wr i t e " p r o v a b l e " code. In a w o r l d where you can i '÷L', (~X), it is impossible to assess when code might or might not execute, or whether and under what circumstances other code might or might not have executed prior to the code in question. Last year, as a test of the APL~PLUS III control structures, I selected a commercial APL utility function written by a reknowned APLer (reknowned for his high-quality code, that is) and attempted to re-write it using control structures. I spent two days, de-diamondizing, printing, drawing colored

DOI: 10.1145/181921.181929

Cite this paper

@inproceedings{Lee1994ControlSI, title={Control structures in APL*Plus III}, author={Christopher C Lee}, booktitle={APLQ}, year={1994} }