[Python-ideas] Modern language design survey for "assign and compare" statements

Steven D'Aprano steve at pearwood.info
Sat May 19 09:41:07 EDT 2018

Thanks for writing up the summary, but you have picked a very narrow 
subset of new languages. One might even say a biased subset. How about 
these new languages?

Elixir, Elm, TypeScript, Hack, Julia, Perl6, Ring, LiveScript, 
Ballerina, Crystal, Opa, Red, Ceylon


At least 10 out of these 13 include some form of assignment 
expressions. If we include the five you selected, 13 out of 18, or 
72% of the sample, include some form of assignment expression.

Details follow below.

Even in the limited set of five languages you chose, 3 out of the 5 
allow some form of assignment expressions:

- Go allows assignment expressions in "if" statements, but not "while";

- Rust allows assignment expressions in both "if" and "while";

- as does Swift;

- Swift also allows assignment in arbitrary expressions, but it returns
  Void (equivalent to returning None).

As for the other languages I found:

Elixir (2011):
- everything is an expression, including assignment

  if current_user = Plug.Conn.get_session(conn, :current_user) do
    Logger.info "User #{current_user.id} logged out"


Elm (2012)
- has "let expressions"


TypeScript (2012)
- a strict superset of Javascript, including assignment expressions

Hack (2014)
- a (not quite full) superset of PHP, including assignment expressions

Julia (2012)
- includes assignment expressions

julia> x = 1
julia> y = (x = 2) + 1
julia> x

Perl 6 a.k.a. Rakudo (2015)

- assignment is an expression:

steve at orac ~ $ perl6 -e "say (my \$x = 32)+100; say \$x"

(the backslashes are escaping the dollar signs from the shell, they're 
not part of the Perl syntax)

- also allows any(?) statement to be used as an expression
  with the `do` prefix

Ring (2016)

Documentation seems fairly poor, more concerned with singing the praises 
of the language than explaining the behaviour in detail, but maybe 
that's just me. But I *think* assignment is not an expression. Using the 
Ring interpreter here:


I tried running this:

    x = 55
    x = (x=99)
    see x

and got the output 0. My interpretation of this is that the x=99 
expression is being interpreted as equals, not assignment.

LiveScript (2011)

- assignment is an expression which returns the value assigned


Ballerina (2017)

- as far as I can tell, assignment is purely a statement


Crystal (2014)

- assignment is an expression which returns the value assigned

I don't know if this link will work:


but if not, try running this:

x = 99;
y = (x = 33) + 1;
print x;
print y;

and the output ought to be 3334.

Opa (2011)

- assignment is an expression; the following two declarations
  are equivalent:

  two = {
    one = 1 // semicolon and newline are equivalent
    one + one

  two = {
    one = 1; one + one // the exact same thing as above


Red (2011)

(not to be confused with the US DOD "RED" language from 1979).

I can't get the documentation to Red to display in a readable form in my 
browser, but it claims to be nearly identical to Rebol.

Wikipedia describes Rebol (and presumably Red) as not having either 
expressions or statements in usual sense. Based on my reading, it is 
kinda-sorta like Forth except without the stack or the postfix syntax. 
The creator of Red describes it:

"About the syntax and semantics, in a nutshell, it's a Lisp without 
parentheses and with infix operator support."

which suggests that assignment could be an expression. There's also a 
"set" function which can assign values, but frankly the Rebol 
programming model confuses me and so I'll count this as a "Possibly, but 
I can't tell for sure so let's say No" for the question of assignment 

Ceylon (2011)

- Ceylon has "let" assignment expressions.


- while loops support assignment


- and switch statements also support a named assignment



More information about the Python-ideas mailing list