J8 Control Structures 
Author Message
 J8 Control Structures


 Eke van Batenburg remarked

 > This year I discovered that Manugistics had implemented
 > controlstructures the classical way.
 > -On the one hand I was glad that finally someone had implemented
 > control structures in APL.
 > -On the other hand I was very disappointed that it was done in the
 > classical-third-generation-language way.

 I was surprised and pleased when Manugistics included
 control structures in their product.   When I read how they had done it
 by essentially exploiting a "syntax hole" in APL,  (i.e. line leading names
 with ":"  are syntax errors in standard APL's) I was not so pleased.
 Leading ":" names are compatible with "old" APL hence this valuable
 enhancement can be ignored  by people so inclined.
 This reminded me of fortran66 versus FORTRAN77.  It took over a decade
 before the very modest improvements in 77 were completely accepted.
 Line leading also leads to modest "code bloat" as some in this
 group have already pointed out.

 To properly implement classical structures you have to break old
 APL  code -- sorry.  That's why I'm delighted with ISI's approach with
 J8.  Recognizing the suite $. and LABELS) were a mistake
 they banished these blemishes and introduced a minimal set
 of inflected control words, (if. do. elseif. else. while. whilest. return.
 break. continue. ...)  J8 control words are stream like and can be
 freely placed in source code.  The following changestr verb illustrates
 the new structures.  This verb is also a good example of an
 algorithm that appears to be scalar (J folks prefer atom) oriented
 but on closer inspection reveals it's whole list at time nature.

 changestr =: 3 : 0
 pairs =. 2 {."(1) _2 [\ <;._1 x.     NB. change table
 cnt=._1 [ lim =. # pairs
 while. lim > cnt=.>:cnt do.          NB. process each change pair
  ('tc') =. cnt { pairs              NB. /target/change (*)=. t c
  if. +./b =. t E. y. do.            NB. next if no target
    u =. b # i. # b                  NB. target starts
    ('lm') =. #&> cnt { pairs        NB. lengths (*)=. l m
    p =. u + 0,+/\(<:# u)$ d =. m - l  NB. change starts
    s =. * d                         NB. reduce < and > to =
    if. s = _1 do.
      b =. 1 #~ # b
      b =. ((l * # u)$ 1 0 #~ m,l-m) (,u +/ i. l)} b
      y. =. b # y.
      if. m = 0 do. continue. end.   NB. next for deletions
    elseif. s = 1 do.
      y. =. y. #~ >: d u} b          NB. first target char replicated
    y.=.(c $~ m *# u) (,p +/i. m)} y.  NB. insert replacements
 end. y.                              NB. altered string

 To run:

 '/replace/this/and/that' changestr 'replace and the other thing'

 John D. Baker

       John D. Baker


Mon, 27 Jan 1997 22:12:11 GMT  
 [ 1 post ] 

 Relevant Pages 

1. j8 availability and features?

2. Control Structure Question

3. More control structures

4. Proposal for control structures in APL

5. Proposal for control structures in APL

6. Proposal for control structures in APL (SAMSON)

7. Control Structures in APL

8. Control Structures in APL

9. Control structures in APL

10. APL Control Structures

11. Control structures.

12. Control structures in APL


Powered by phpBB® Forum Software