Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!utnut!cs.utexas.edu!zaphod.mps.ohio-state.edu!wupost!csus.edu!sfsuvax1.sfsu.edu!vpcsc4
From: vpcsc4@sfsuvax1.sfsu.edu (__)
Subject: Re: Control Stuctures in APL
Message-ID: <1993Apr10.045751.26616@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <734283300.AA03137@blkcat.UUCP>
Date: Sat, 10 Apr 1993 04:57:51 GMT
Lines: 98

In article David.Michelson writes:
>There ARE some control structures in APL:
>
>All dialects support array handling:  1000 + iota 25   does a kind of DO loop.
>                                      +/ iota 100      does another.
>
>Some dialects support diamond:  you can only branch to a line beginning,
>  allowing you to do setup stuff no one can interrupt and branch past.

   NB.  I'd say you are streching it calling iota a control structure.
   NB.  And diamond is not a control structure.
   NB.  But the good news is that Manugistics is adding new structured control
   NB.  structures and features to their dialect. This might even lead to
   NB.  renaming their product to INCA for "It's not APL". Also, the language A
   NB.  at Morgan Stanely also has some structured control constructs.

   NB. Some do not consider J a dialect of APL (I don't), but it does have some
   NB. interesting control structures APL does not have. Here are some:
   
   NB. example of "power" which can be called "for"
   increm =. >:
   power =. ^:
   increm power (5) 0
5
   
   NB. example of "chain" which can be called "while"
   increm =. >:
   while =. ^:
   lessThan3 =. <&3
   increm while lessThan3 (0)
3
   
   NB. example of agenda which can be call "if"
   if =. @.
   equalTo1 =. 1&=
   zero =. 'zero'"_
   one =.  'one'"_
   test =. zero`one if equalTo1
   test 1
one
   test 0
zero
   
   NB. example of agenda which can be call "case"
   two =.  'two'"_
   case =. @.
   shape =. $
   scalar =. ''&shape
   condition =. scalar@((0 1 2)&= # (0 1 2)"_) 
   anotherTest =. zero`one`two case condition

   anotherTest 0
zero
   anotherTest 1
one
   anotherTest 2
two
   
   NB. Also, J allows for MISD (parallel) computations.
   double =. +:
   square =. *:
   neg =. -
   evokeVerbList=. `:0
   neg`square`double evokeVerbList (5)
_5 25 10

   NB. same thing over the zero cells of the input
   (neg`square`double`:0)"0 ( 3 4 5)
_3  9  6
_4 16  8
_5 25 10
  
   NB. Now lets look at a special feature of the copula
   NB. This hack is useful in getting all the data from a
   NB. fullscreen input window.
 
   box =. <
   x =. 's1';'s2'
   (x) =. (box@neg)`(box@square) evokeVerbList (4)
   s1
_4
   s2 
16
   (x) =. ((box@neg)`(box@square)evokeVerbList) "1 (4 8 16)
   s1
_4 _8 _16
   s2
16 64 256

  NB. This sums it up for the "fundamental" functional control stuctures.
  NB. There are a few other items one might think of as
  NB. control stuctures such as "obverse and under", and
  NB. adverse (J's []TRAP).

  NB. For explicit definition, J also has APL's "branch" ,
      APL's "execute" called "do".

  <'Emmett'
