No Assignment in Conditional/PROPOSAL: Assignment expression 
Author Message
 No Assignment in Conditional/PROPOSAL: Assignment expression

MLH>   while expr(line = readline, line):

All the proposals to allow assignments in while conditions, whetehr with
special syntax (:=, from etc.) have a few flaws:

1. There is no reason to restrict it to while. They can be as effective in
   if, or even in a boolean assignment :=(
2. There are more general cases, like:
        while (
                do_something()
                line = readline()
                do_something_else()
               line)
            process()

which would of course translate to real python as:

        while 1:
                do_something()
                line = readline()
                do_something_else()
                if not line: break
                process()

which unfortunately obscures the control flow a bit.

Both problems can be solved by introduce a new concept into python: a
compund expression, which would consist of a parenthesised suite of
statements followed by an expression (each separated by a semicolon).
The meaning is obvious (execute the statements and yield the expression).

e.g.:

        while ( do_something();
                line = readline();
                do_something_else();
                line):
            process()

I would suggest to make the semicolon obligatory and not allw it to be
replaced by indentation as it would otherwise more difficult to parse, and
it prevents errors which could occur if the semicolons are not present,
especially when this construct was not intended but a parentheses would be
forgotten.

This construct could also be used to get statements in lambda expressions.
The proposal isn't very original, as Algol 68 had exactly this construct.
--

URL: http://www.*-*-*.com/ ~piet [PGP]



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression

Quote:


> MLH>   while expr(line = readline, line):
[...]

> Both problems can be solved by introduce a new concept into python: a
> compund expression, which would consist of a parenthesised suite of
> statements followed by an expression (each separated by a semicolon).
> The meaning is obvious (execute the statements and yield the expression).

> e.g.:

>    while ( do_something();
>            line = readline();
>            do_something_else();
>            line):
>        process()

I suggested this earlier... (Though I only used one statement and one
expression -- I got the idea from a minimal language in a compiler
textbook. The construct there was simply (stmt;expr), allowing only
the two. That's probably enough for the assignment problem, though.)

--

  Magnus          
  Lie              



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression

Quote:

>    while ( do_something();
>            line = readline();
>            do_something_else();
>            line):
>        process()

This seems like misuse to me ;)

  while (line=readline; line):
      process()

however, seems quite nice. Less confusing than ":=", I think.

Quote:

> I would suggest to make the semicolon obligatory and not allw it to be
> replaced by indentation as it would otherwise more difficult to parse, and
> it prevents errors which could occur if the semicolons are not present,
> especially when this construct was not intended but a parentheses would be
> forgotten.

> This construct could also be used to get statements in lambda expressions.
> The proposal isn't very original, as Algol 68 had exactly this construct.

Well, maybe that's a plus...

--

  Magnus          
  Lie              



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression

Quote:
> Both problems can be solved by introduce a new concept into python: a
> compund expression, which would consist of a parenthesised suite of
> statements followed by an expression (each separated by a semicolon).
> The meaning is obvious (execute the statements and yield the expression).

> e.g.:

>    while ( do_something();
>            line = readline();
>            do_something_else();
>            line):
>        process()

> I would suggest to make the semicolon obligatory and not allw it to be
> replaced by indentation as it would otherwise more difficult to parse, and
> it prevents errors which could occur if the semicolons are not present,
> especially when this construct was not intended but a parentheses would be
> forgotten.

> This construct could also be used to get statements in lambda expressions.
> The proposal isn't very original, as Algol 68 had exactly this construct.

Not bad!

--Guido van Rossum (home page: http://www.python.org/~guido/)



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression
[snippage]

Quote:
> e.g.:

>         while ( do_something();
>                 line = readline();
>                 do_something_else();
>                 line):
>             process()

I can see this as a valid lambda proposal:

        map ((x,y) { do_something(x);
                     line=readline();
                     do_something_else(y);
                     line + x + y },
             myListOfTuples)

even with a convoluted example like that it doesn't look too bad.

As an assignment expression substitution is too verbose and not as
elegant as ':=' though...

-- bjorn



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression
...

Quote:
>         while ( do_something();
>                 line = readline();
>                 do_something_else();
>                 line):
>             process()

IMHO, this is the best proposal I've seen so far!

Quote:
> I would suggest to make the semicolon obligatory and not allw it to be
> replaced by indentation as it would otherwise more difficult to parse, and
> it prevents errors which could occur if the semicolons are not present,
> especially when this construct was not intended but a parentheses would be
> forgotten.

> This construct could also be used to get statements in lambda expressions.
> The proposal isn't very original, as Algol 68 had exactly this construct.

Much better than two assignments, very obvious, very powerful,
and improvement to poor little Lambda, what else should we want?
I hope there is no hidden drawback and it makes it.

cheers - chris

--

Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.skyport.net
10553 Berlin                 :     PGP key -> http://pgp.ai.mit.edu/
     we're tired of banana software - shipped green, ripens at home



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression

[list of expressions and assignments separated by ";" evaluates to last one
in list]

Quote:

>Not bad!

This could be very nice.  Quickly compare and contrast the following two
statements, though:

while (x=f(); x):
  print x

while (x==f(); x):
  print x

Of course, this is a pretty silly typo, and will only go uncaught if x isn't
assigned prior to the loop and isn't in globals(), but...

Mmmm... really really long expressions
Evan Simpson



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression
...
| Both problems can be solved by introduce a new concept into python: a
| compund expression, which would consist of a parenthesised suite of
| statements followed by an expression (each separated by a semicolon).
| The meaning is obvious (execute the statements and yield the expression).
|
| e.g.:
|
|       while ( do_something();
|               line = readline();
|               do_something_else();
|               line):
|           process()
|
| I would suggest to make the semicolon obligatory and not allw it to be
| replaced by indentation as it would otherwise more difficult to parse, and
| it prevents errors which could occur if the semicolons are not present,
| especially when this construct was not intended but a parentheses would be
| forgotten.

If potential application in lambda expressions isn't a major part of
the attraction, I'd think a block structure would be so much more
readable for people who have gotten used to the language, e.g.,

    while:
        do_something()
        line = readline()
        do_something_else()
    break line:
        process()

I have had to skip most of the never-ending cycle of proposals in this
series, but I'm sure a couple of variations on that theme have already
been proposed.  The structure scales better where do_something() might
actually be quite a few lines of code, it seems to me.

        Donn Cave, University Computing Services, University of Washington



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression

Quote:

> If potential application in lambda expressions isn't a major part of
> the attraction, I'd think a block structure would be so much more
> readable for people who have gotten used to the language, e.g.,

>     while:
>         do_something()
>         line = readline()
>         do_something_else()
>     break line:
>           process()

> I have had to skip most of the never-ending cycle of proposals in this
> series, but I'm sure a couple of variations on that theme have already
> been proposed.  The structure scales better where do_something() might
> actually be quite a few lines of code, it seems to me.

As a coder (as opposed to a language philosopher) I must agree that Donn's
structure seems more "Pythonish" (adverbial form: "Pythonical"?).

In my unrequested opinion, however, I must admit that this does seem like
much ado about very little. After all, although

    while 1:
       ...
       break

may admittedly not be the most elegant of constructs, Python is a working
scripting tool, not a prissy teaching example.

Sincere-ly,
--- Robert

--------------------------------
Robert Meegan
MCIWorldCom - Cedar Rapids, Iowa
319.375.2416



Sat, 14 Jul 2001 03:00:00 GMT  
 No Assignment in Conditional/PROPOSAL: Assignment expression

Quote:


[...]
> As a coder (as opposed to a language philosopher) I must agree that Donn's
> structure seems more "Pythonish" (adverbial form: "Pythonical"?).

Adjective: "Pythonesque"
Adverb:    "Pythonesquely"

--

  Magnus          
  Lie              



Sun, 15 Jul 2001 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. PROPOSAL: Assignment expression

2. "multiple assignment in conditional"

3. conditional signal assignment

4. Conditional assignments using generate

5. Conditional Signal Assignments inside Processes?

6. inline assignments in conditionals

7. Against assignment in conditional nor while

8. RFC: Assignment in Conditional

9. Proposal: new operator: '<-' (for assignments)

10. Proposal: Constructors, Assignment [LONG]

11. proposal for new assignment operators

12. Proposal: natural extension of assignment notation

 

 
Powered by phpBB® Forum Software