Control structures. 
Author Message
 Control structures.

Quote:
---- William Chang writes:
>Here are three orthogonal, complementary proposals for adding control
>structures to APL.  Critiques are welcome.

>(1) Controlled statements

><WHILE>  {control} -> {block}
><IF>     (control) -> {if-block} {optional-else-block}
><CASE>   (control) -> (case1) {block1} ... (caseN) {blockN} () {default}

>(2) Controlled expressions

><EXPR>   {expr1} {expr2} ... {exprN} [control]

>(3) Local functions and subroutines

><GOSUB>  (control) -> label(val1;val2;...;valN)
><DEFN>   label (arg1;arg2;...;argN) ;local1;...;localK : {block}
><RETURN> <- optional-result

----- Kim Whitelaw replies:

- Show quoted text -

Quote:
>I prefer the Manugistics control structures over these proposals
>for the following reasons:

>1) The resulting code is easier to read and understand (my opinion :)
>2) Manugistic's control structures are probably easier to implement.
>3) They are faster than branches with Manugistics implementation.
>4) The colon prefixed key words (especially with color highlighting) make
>   the structure of an algorithm apparent at a glance.

>For the Manugistic's control structures, I dont like the following:
>1) IF statements require at least 3 statements (diamonds can separate the parts)
>       :if condition
>          statement
>       :endif
>   For the simple cases, I would prefer to write something like
>       :if condition :then statement  (i.e. BASIC's conventions)

>2) :GOTO and :RETURN seem useless.  :RETURN is not even as powerful as the
>   standard APL technique of branching to 0, since it is unconditional.

>3) The control structures can only be used within functions

(Sorry to repeat such a lot of lines that most of you have already
read, but:)
It seems to me that such a survey and comments is a very good base to
work on.
Unfortunately I have to sigh off from this discussion for a couple of
weeks (the ISO standards committee starts next hour and after this ISO,
APL94 followes).
...............................................................
Let me just add a couple of remarks.
Could you extend your proposal a bit, Bill? Some things are not so
clear to me. For example what is control in your first example?
And why is the first proposal read topdown and the next bottom up?
I would like to have added how in particular you see the regular CASE,
IF WHILE and DO in proposal 2.
.................................................................
Let me add a slight variant of proposal 2 , which I will call proposal
4.
As much as proposal [2] is based on the analogy of indexing, mine is
based on the analogy of replicate (with left and right argument
swapped: left are "lazy evaluated" array of expressions, right is the
replication number(s).:
[..] (exprn)...(expr.2)(expr.1)->control [...]
if any expression is broken by newlines that block should be enclose
by braes.

This enables:
<IF for control 0/1>       (expr)->A>B
<DOLOOP for control any #> (expr)->20+3-B
<IF/ELSE for control
     is vector 0 1 or 1 0> (expr2)(expr1)->1 0=A>B
<WHILE for control
       is negative number> (exp)-> - A>B
       (reevaluation of negative "-A>B" until negative gets 0)
<CASE>                     (exp7)(exp6)...(exp1)->DAY=1 2 3 4 5 6 7
<NEW INTERESTING iMPLICATION>     (exp2)(exp1)->15 20
  (exp1 is done 20 times, next exp1 15 times)
<ANOTHER ONE>              (exp7)(exp6)...(exp1)->0 2 0 0 -2 0 1
  (exp1 is done once, exp3 done twice. exp 6 done twice and next
control is reevaluated untill all control is 0 or positive)
<BLOCKING>
[..]   exp1)}->DAY=1 2 3 4 5 6 7
[..]      (cont.
[..]      (cont
[..]      exp2)
[..]      (cont
[..]      ((exp3c)(exp3b)(exp3a)->another control in exp3)
[..]      (exp4)
[..]      a broken exp5)}
[..]      {end of broken exp5
[..]      (exp6)
[..]   {(exp7)

Sorry, my meeting starts now, now time for evaluateion. See all of you
after 2 weeks, some of you next week at APL94.

............................................Eke van Batenburg



Sat, 22 Feb 1997 15:11:32 GMT  
 Control structures.

Quote:
>---- William Chang writes:
>.................................................................
>Let me add a slight variant of proposal 2 , which I will call proposal
>4.
>As much as proposal [2] is based on the analogy of indexing, mine is
>based on the analogy of replicate (with left and right argument
>swapped: left are "lazy evaluated" array of expressions, right is the
>replication number(s).:
>[..] (exprn)...(expr.2)(expr.1)->control [...]
>if any expression is broken by newlines that block should be enclose
>by braes.

>This enables:
><IF for control 0/1>       (expr)->A>B
><DOLOOP for control any #> (expr)->20+3-B
><IF/ELSE for control
>     is vector 0 1 or 1 0> (expr2)(expr1)->1 0=A>B
><WHILE for control
>       is negative number> (exp)-> - A>B
>       (reevaluation of negative "-A>B" until negative gets 0)
><CASE>                     (exp7)(exp6)...(exp1)->DAY=1 2 3 4 5 6 7
><NEW INTERESTING iMPLICATION>     (exp2)(exp1)->15 20
>  (exp1 is done 20 times, next exp1 15 times)
><ANOTHER ONE>              (exp7)(exp6)...(exp1)->0 2 0 0 -2 0 1
>  (exp1 is done once, exp3 done twice. exp 6 done twice and next
>control is reevaluated untill all control is 0 or positive)
><BLOCKING>
>[..]   exp1)}->DAY=1 2 3 4 5 6 7
>[..]      (cont.
>[..]      (cont
>[..]      exp2)
>[..]      (cont
>[..]      ((exp3c)(exp3b)(exp3a)->another control in exp3)
>[..]      (exp4)
>[..]      a broken exp5)}
>[..]      {end of broken exp5
>[..]      (exp6)
>[..]   {(exp7)

This "feature" appeared in J for some time as "suite". Suite is
EVIL. It has the following interesting properties:

a. It is of almost zero utility in practical applications, except
   for the most simple control structures [for loop]

b. It is nearly impossible to compile efficiently [at all?] except
   in the "for loop" case.

c. It is a pain in the {*filter*}for people reading code, maintaining it,
   debugging  it, etc.

In short,  it's Bad Design. Needlessly complicated, with features that
are more likely to cause problems than help in the process of
writing readable, maintainable, efficient programs.

Suite was deleted from J recently. It doesn't belong in APL either.

Bob



Sat, 22 Feb 1997 23:24:57 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Control Structure Question

2. More control structures

3. Proposal for control structures in APL

4. Proposal for control structures in APL

5. Proposal for control structures in APL (SAMSON)

6. Control Structures in APL

7. Control Structures in APL

8. Control structures in APL

9. APL Control Structures

10. Control structures in APL

11. Control structures; discussion or proposal

12. Control structures in APL

 

 
Powered by phpBB® Forum Software