ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:119663] [Ruby master Bug#20858] multiple parallel assignments are inconsistent
@ 2024-11-01  0:20 daveola (David Stellar) via ruby-core
  2024-11-01  0:42 ` [ruby-core:119664] " mame (Yusuke Endoh) via ruby-core
  2024-11-01 17:42 ` [ruby-core:119681] " daveola (David Stellar) via ruby-core
  0 siblings, 2 replies; 3+ messages in thread
From: daveola (David Stellar) via ruby-core @ 2024-11-01  0:20 UTC (permalink / raw)
  To: ruby-core; +Cc: daveola (David Stellar)

Issue #20858 has been reported by daveola (David Stellar).

----------------------------------------
Bug #20858: multiple parallel assignments are inconsistent
https://bugs.ruby-lang.org/issues/20858

* Author: daveola (David Stellar)
* Status: Open
* ruby -v: ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I may have terminology wrong, so apologies.  For this bug I'm going to use "multiple assignment" to refer to using multiple assignment operators in a line, such as:

``` ruby
a = b = c = 1
```

And then parallel assignment to refer to doing multiple assignments at the same time using tuples, such as:

``` ruby
a,b = 1, 2
```

Unfortunately combining these is inconsistent.  First of all, just doing this:

``` ruby
a,b = c,d = 3,4
```

Gives us:  **"undefined local variable or method `c' for main (NameError)"**

So if we work around that by defining all our variables, we then get unexpected results:

``` ruby
a = b = c = d = 'foobar'

a,b = c,d = 3,4

puts "Got:  a=#{a} b=#{b} and c=#{c} d=#{d}"
# Got:  a=foobar b=3 and c=foobar d=3

c,d = 3,4
a,b = c,d

puts "Got:  a=#{a} b=#{b} and c=#{c} d=#{d}"
# Got:  a=3 b=4 and c=3 d=4
```


I can imagine that if multiple parallel assignment is not supported that a,b will not get set properly, but it does not follow that c would be undefined by the expression.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:119664] [Ruby master Bug#20858] multiple parallel assignments are inconsistent
  2024-11-01  0:20 [ruby-core:119663] [Ruby master Bug#20858] multiple parallel assignments are inconsistent daveola (David Stellar) via ruby-core
@ 2024-11-01  0:42 ` mame (Yusuke Endoh) via ruby-core
  2024-11-01 17:42 ` [ruby-core:119681] " daveola (David Stellar) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-11-01  0:42 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20858 has been updated by mame (Yusuke Endoh).


Currently, `a, b = c, d = 3, 4` is interpreted as `a, b = c, (d = 3, 4)`. Whether it is good or not.

----------------------------------------
Bug #20858: multiple parallel assignments are inconsistent
https://bugs.ruby-lang.org/issues/20858#change-110320

* Author: daveola (David Stellar)
* Status: Open
* ruby -v: ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I may have terminology wrong, so apologies.  For this bug I'm going to use "multiple assignment" to refer to using multiple assignment operators in a line, such as:

``` ruby
a = b = c = 1
```

And then parallel assignment to refer to doing multiple assignments at the same time using tuples, such as:

``` ruby
a,b = 1, 2
```

Unfortunately combining these is inconsistent.  First of all, just doing this:

``` ruby
a,b = c,d = 3,4
```

Gives us:  **"undefined local variable or method `c' for main (NameError)"**

So if we work around that by defining all our variables, we then get unexpected results:

``` ruby
a = b = c = d = 'foobar'

a,b = c,d = 3,4

puts "Got:  a=#{a} b=#{b} and c=#{c} d=#{d}"
# Got:  a=foobar b=3 and c=foobar d=3

c,d = 3,4
a,b = c,d

puts "Got:  a=#{a} b=#{b} and c=#{c} d=#{d}"
# Got:  a=3 b=4 and c=3 d=4
```


I can imagine that if multiple parallel assignment is not supported that a,b will not get set properly, but it does not follow that c would be undefined by the expression.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:119681] [Ruby master Bug#20858] multiple parallel assignments are inconsistent
  2024-11-01  0:20 [ruby-core:119663] [Ruby master Bug#20858] multiple parallel assignments are inconsistent daveola (David Stellar) via ruby-core
  2024-11-01  0:42 ` [ruby-core:119664] " mame (Yusuke Endoh) via ruby-core
@ 2024-11-01 17:42 ` daveola (David Stellar) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: daveola (David Stellar) via ruby-core @ 2024-11-01 17:42 UTC (permalink / raw)
  To: ruby-core; +Cc: daveola (David Stellar)

Issue #20858 has been updated by daveola (David Stellar).


mame (Yusuke Endoh) wrote in #note-1:
> Currently, `a, b = c, d = 3, 4` is interpreted as `a, b = c, (d = 3, 4)`. Whether it is good or not.

Ah - that's a good point.  So it can be fixed with:   `a, b = (c, d = 3, 4)`
I didn't see that possibility.  Is there a clear reason why it's interpreted like this?


----------------------------------------
Bug #20858: multiple parallel assignments are inconsistent
https://bugs.ruby-lang.org/issues/20858#change-110341

* Author: daveola (David Stellar)
* Status: Open
* ruby -v: ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I may have terminology wrong, so apologies.  For this bug I'm going to use "multiple assignment" to refer to using multiple assignment operators in a line, such as:

``` ruby
a = b = c = 1
```

And then parallel assignment to refer to doing multiple assignments at the same time using tuples, such as:

``` ruby
a,b = 1, 2
```

Unfortunately combining these is inconsistent.  First of all, just doing this:

``` ruby
a,b = c,d = 3,4
```

Gives us:  **"undefined local variable or method `c' for main (NameError)"**

So if we work around that by defining all our variables, we then get unexpected results:

``` ruby
a = b = c = d = 'foobar'

a,b = c,d = 3,4

puts "Got:  a=#{a} b=#{b} and c=#{c} d=#{d}"
# Got:  a=foobar b=3 and c=foobar d=3

c,d = 3,4
a,b = c,d

puts "Got:  a=#{a} b=#{b} and c=#{c} d=#{d}"
# Got:  a=3 b=4 and c=3 d=4
```


I can imagine that if multiple parallel assignment is not supported that a,b will not get set properly, but it does not follow that c would be undefined by the expression.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-01 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-01  0:20 [ruby-core:119663] [Ruby master Bug#20858] multiple parallel assignments are inconsistent daveola (David Stellar) via ruby-core
2024-11-01  0:42 ` [ruby-core:119664] " mame (Yusuke Endoh) via ruby-core
2024-11-01 17:42 ` [ruby-core:119681] " daveola (David Stellar) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).