Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't do
anything :)/
···
--
Wizard
james@supmenow.com
+44 7523 279 698
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't do
anything :)/
--
Wizard
james@supmenow.com
+44 7523 279 698
I think that the existing syntax for “??” handles this need fairly well without requiring an additional assignment operator:
a = a ??
- Greg
On Dec 15, 2015, at 2:53 PM, James Campbell via swift-evolution <swift-evolution@swift.org> wrote:
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't do anything :)/
--
Wizard
james@supmenow.com <mailto:james@supmenow.com>
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
I filed this as rdar://22469833. It was marked as a duplicate of
rdar://19833281.
Jacob Bandes-Storch
On Tue, Dec 15, 2015 at 2:53 PM, James Campbell via swift-evolution < swift-evolution@swift.org> wrote:
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't
do anything :)/--
Wizard
james@supmenow.com
+44 7523 279 698_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
And also rdar://22469833: Swift: coalescing assignment (??=) operator
Jacob
On Tue, Dec 15, 2015 at 3:00 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:
I filed this as rdar://22469833. It was marked as a duplicate of
rdar://19833281.Jacob Bandes-Storch
On Tue, Dec 15, 2015 at 2:53 PM, James Campbell via swift-evolution < > swift-evolution@swift.org> wrote:
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't
do anything :)/--
Wizard
james@supmenow.com
+44 7523 279 698_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
I think that the existing syntax for “??” handles this need fairly well without requiring an additional assignment operator:
a = a ??
When the variable is `a`, sure. When it’s `scoreboardViewController.selectedScoreboard`, not so much.
+1 from me, though I prefer the `??=` spelling to match the `??` operator more closely.
--
Brent Royal-Gordon
Architechies
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?
This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil {
lhs = rhs() } }
However, the use of "inout" will always cause the didSets to be triggered
at the call site, when just using if-statements instead wouldn't have done
so.
Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution < swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly well
without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??` operator
more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
Good idea – I miss the ||= conditional assignment operator from Ruby.
Ash
On Dec 15, 2015, at 5:53 PM, James Campbell via swift-evolution <swift-evolution@swift.org> wrote:
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't do anything :)/
--
Wizard
james@supmenow.com
+44 7523 279 698_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
Good idea – I miss the ||= conditional assignment operator from Ruby.
Ash
---------- Forwarded message ----------
From: Ash Furrow <ash@ashfurrow.com>
Date: Tue, Dec 15, 2015 at 10:58 PM
Subject: Re: [swift-evolution] Optional Setting
To: James Campbell <james@supmenow.com>
On Dec 15, 2015, at 5:53 PM, James Campbell via swift-evolution < swift-evolution@swift.org> wrote:
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't do
anything :)/
--
Wizard
james@supmenow.com
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
--
Wizard
james@supmenow.com
+44 7523 279 698
Me too :) so handy!
On Tue, Dec 15, 2015 at 11:03 PM, Ash Furrow via swift-evolution < swift-evolution@swift.org> wrote:
Good idea – I miss the ||= conditional assignment operator from Ruby.
Ash
On Dec 15, 2015, at 5:53 PM, James Campbell via swift-evolution < > swift-evolution@swift.org> wrote:
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't
do anything :)/--
Wizard
james@supmenow.com
+44 7523 279 698_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
--
Wizard
james@supmenow.com
+44 7523 279 698
If it has a value already the nit wouldn't call anything as it technically
hasn't been set. Only if it already has a value does it try and set
something in which case the didSet is called :)
On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution < swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil {
lhs = rhs() } }However, the use of "inout" will always cause the didSets to be triggered
at the call site, when just using if-statements instead wouldn't have done
so.Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution < > swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly well
without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??` operator
more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
--
Wizard
james@supmenow.com
+44 7523 279 698
Yes the ??= is a better syntax.
On Tue, Dec 15, 2015 at 11:10 PM, Brent Royal-Gordon <brent@architechies.com > wrote:
> I think that the existing syntax for “??” handles this need fairly well
without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??` operator
more closely.--
Brent Royal-Gordon
Architechies
--
Wizard
james@supmenow.com
+44 7523 279 698
There’s already
a = a ??
which is a shorthand for
a = a ? a :
For some reason I find it slightly weird to see ?= but that might just be
because I’m not used to seeing it.
On Tue, Dec 15, 2015 at 11:53 PM, James Campbell via swift-evolution < swift-evolution@swift.org> wrote:
Would be great to have a ?= syntax.
So if
var a: [String]? is nil then
a ?=
will set it with a new array but if it already has a value then it won't
do anything :)/--
Wizard
james@supmenow.com
+44 7523 279 698_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
I agree that would be nice. Just pointing out that it's nontrivial. If you
implement this custom operator today, you get different behavior.
Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com> wrote:
If it has a value already the nit wouldn't call anything as it technically
hasn't been set. Only if it already has a value does it try and set
something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution > <swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil {
lhs = rhs() } }However, the use of "inout" will always cause the didSets to be triggered
at the call site, when just using if-statements instead wouldn't have done
so.Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution < >> swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly
well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??`
operator more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698
:) Wasn't expecting it to be trivial. but yeah if it could somehow be short
circuited so didSet, willSet isn't called when there is a value already.
that would be awesome.
Could the willSet, didSet behaviour be tied to the = behaviour ? in your
example above the operation ultimately cascades into a = operation.
Same with operations such as *= or /= ultimately it has to do a = operation
to set the new calculated value.
On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:
I agree that would be nice. Just pointing out that it's nontrivial. If you
implement this custom operator today, you get different behavior.Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com> > wrote:
If it has a value already the nit wouldn't call anything as it
technically hasn't been set. Only if it already has a value does it try and
set something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution >> <swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil
{ lhs = rhs() } }However, the use of "inout" will always cause the didSets to be
triggered at the call site, when just using if-statements instead wouldn't
have done so.Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution >>> <swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly
well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??`
operator more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698
--
Wizard
james@supmenow.com
+44 7523 279 698
It's possible that @_transparent <https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst> is handled early enough in the compiler that we actually would get this behavior. I'm not sure, though.
+1 from me whether or not didSet is always called, though. "a = a ?? b" always calls didSet anyway.
Jordan
P.S. There's nothing particularly useful in the Radar, except that together with the dups there are three suggested spellings: "=?", "?=", and "??=". My vote is with Brent for "??=".
On Dec 15, 2015, at 15:26 , James Campbell via swift-evolution <swift-evolution@swift.org> wrote:
:) Wasn't expecting it to be trivial. but yeah if it could somehow be short circuited so didSet, willSet isn't called when there is a value already. that would be awesome.
Could the willSet, didSet behaviour be tied to the = behaviour ? in your example above the operation ultimately cascades into a = operation.
Same with operations such as *= or /= ultimately it has to do a = operation to set the new calculated value.
On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch <jtbandes@gmail.com <mailto:jtbandes@gmail.com>> wrote:
I agree that would be nice. Just pointing out that it's nontrivial. If you implement this custom operator today, you get different behavior.Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com <mailto:james@supmenow.com>> wrote:
If it has a value already the nit wouldn't call anything as it technically hasn't been set. Only if it already has a value does it try and set something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
One possible caveat is with custom setters.If "a" already has a value, does "a ??= b" call the custom setter/willSet/didSet, or does it see the nil and short-circuit?
This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil { lhs = rhs() } }
However, the use of "inout" will always cause the didSets to be triggered at the call site, when just using if-statements instead wouldn't have done so.
Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
> I think that the existing syntax for “??” handles this need fairly well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s `scoreboardViewController.selectedScoreboard`, not so much.
+1 from me, though I prefer the `??=` spelling to match the `??` operator more closely.
--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com <mailto:james@supmenow.com>
+44 7523 279 698 <tel:%2B44%207523%20279%20698>--
Wizard
james@supmenow.com <mailto:james@supmenow.com>
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
Would there be any caveats in introducing something like this, given the
raciness of the operator? I guess it's not really a big deal — the other
compound assignment operators (+=, -=, etc.) have the same problem.
I'm not hearing much argument; sounds like many are in favor. I'd be happy
to flesh out my radar into a "??=" proposal this evening, or someone else
can do it if they'd like.
Jacob
On Tue, Dec 15, 2015 at 4:12 PM, Jordan Rose <jordan_rose@apple.com> wrote:
It's possible that @_transparent
<https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst> is
handled early enough in the compiler that we actually would get this
behavior. I'm not sure, though.+1 from me whether or not didSet is always called, though. "a = a ?? b"
always calls didSet anyway.Jordan
P.S. There's nothing particularly useful in the Radar, except that
together with the dups there are three suggested spellings: "=?", "?=", and
"??=". My vote is with Brent for "??=".On Dec 15, 2015, at 15:26 , James Campbell via swift-evolution < > swift-evolution@swift.org> wrote:
:) Wasn't expecting it to be trivial. but yeah if it could somehow be
short circuited so didSet, willSet isn't called when there is a value
already. that would be awesome.Could the willSet, didSet behaviour be tied to the = behaviour ? in your
example above the operation ultimately cascades into a = operation.Same with operations such as *= or /= ultimately it has to do a =
operation to set the new calculated value.On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch <jtbandes@gmail.com> > wrote:
I agree that would be nice. Just pointing out that it's nontrivial. If
you implement this custom operator today, you get different behavior.Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com> >> wrote:
If it has a value already the nit wouldn't call anything as it
technically hasn't been set. Only if it already has a value does it try and
set something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution >>> <swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs ==
nil { lhs = rhs() } }However, the use of "inout" will always cause the didSets to be
triggered at the call site, when just using if-statements instead wouldn't
have done so.Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution >>>> <swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly
well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??`
operator more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698--
Wizard
james@supmenow.com
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
+1 on ??= for consistency with ??
Sent from my iPad
On Dec 15, 2015, at 6:12 PM, Jordan Rose via swift-evolution <swift-evolution@swift.org> wrote:
It's possible that @_transparent is handled early enough in the compiler that we actually would get this behavior. I'm not sure, though.
+1 from me whether or not didSet is always called, though. "a = a ?? b" always calls didSet anyway.
Jordan
P.S. There's nothing particularly useful in the Radar, except that together with the dups there are three suggested spellings: "=?", "?=", and "??=". My vote is with Brent for "??=".
On Dec 15, 2015, at 15:26 , James Campbell via swift-evolution <swift-evolution@swift.org> wrote:
:) Wasn't expecting it to be trivial. but yeah if it could somehow be short circuited so didSet, willSet isn't called when there is a value already. that would be awesome.
Could the willSet, didSet behaviour be tied to the = behaviour ? in your example above the operation ultimately cascades into a = operation.
Same with operations such as *= or /= ultimately it has to do a = operation to set the new calculated value.
On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:
I agree that would be nice. Just pointing out that it's nontrivial. If you implement this custom operator today, you get different behavior.Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com> wrote:
If it has a value already the nit wouldn't call anything as it technically hasn't been set. Only if it already has a value does it try and set something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.If "a" already has a value, does "a ??= b" call the custom setter/willSet/didSet, or does it see the nil and short-circuit?
This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil { lhs = rhs() } }
However, the use of "inout" will always cause the didSets to be triggered at the call site, when just using if-statements instead wouldn't have done so.
Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s `scoreboardViewController.selectedScoreboard`, not so much.
+1 from me, though I prefer the `??=` spelling to match the `??` operator more closely.
--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698--
Wizard
james@supmenow.com
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
Cool would be happy for you to do it :) if you time, almost night here so
:) but happy for you to quote me in the proposal.
On Wed, Dec 16, 2015 at 12:17 AM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:
Would there be any caveats in introducing something like this, given the
raciness of the operator? I guess it's not really a big deal — the other
compound assignment operators (+=, -=, etc.) have the same problem.I'm not hearing much argument; sounds like many are in favor. I'd be happy
to flesh out my radar into a "??=" proposal this evening, or someone else
can do it if they'd like.Jacob
On Tue, Dec 15, 2015 at 4:12 PM, Jordan Rose <jordan_rose@apple.com> > wrote:
It's possible that @_transparent
<https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst> is
handled early enough in the compiler that we actually would get this
behavior. I'm not sure, though.+1 from me whether or not didSet is always called, though. "a = a ?? b"
always calls didSet anyway.Jordan
P.S. There's nothing particularly useful in the Radar, except that
together with the dups there are three suggested spellings: "=?", "?=", and
"??=". My vote is with Brent for "??=".On Dec 15, 2015, at 15:26 , James Campbell via swift-evolution < >> swift-evolution@swift.org> wrote:
:) Wasn't expecting it to be trivial. but yeah if it could somehow be
short circuited so didSet, willSet isn't called when there is a value
already. that would be awesome.Could the willSet, didSet behaviour be tied to the = behaviour ? in
your example above the operation ultimately cascades into a = operation.Same with operations such as *= or /= ultimately it has to do a =
operation to set the new calculated value.On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch <jtbandes@gmail.com >> > wrote:
I agree that would be nice. Just pointing out that it's nontrivial. If
you implement this custom operator today, you get different behavior.Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com> >>> wrote:
If it has a value already the nit wouldn't call anything as it
technically hasn't been set. Only if it already has a value does it try and
set something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via >>>> swift-evolution <swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs ==
nil { lhs = rhs() } }However, the use of "inout" will always cause the didSets to be
triggered at the call site, when just using if-statements instead wouldn't
have done so.Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution >>>>> <swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly
well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??`
operator more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698--
Wizard
james@supmenow.com
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
--
Wizard
james@supmenow.com
+44 7523 279 698
On second thoughts, I'm preparing one :)
On Wed, Dec 16, 2015 at 12:24 AM, James Campbell <james@supmenow.com> wrote:
Cool would be happy for you to do it :) if you time, almost night here so
:) but happy for you to quote me in the proposal.On Wed, Dec 16, 2015 at 12:17 AM, Jacob Bandes-Storch <jtbandes@gmail.com> > wrote:
Would there be any caveats in introducing something like this, given the
raciness of the operator? I guess it's not really a big deal — the other
compound assignment operators (+=, -=, etc.) have the same problem.I'm not hearing much argument; sounds like many are in favor. I'd be
happy to flesh out my radar into a "??=" proposal this evening, or someone
else can do it if they'd like.Jacob
On Tue, Dec 15, 2015 at 4:12 PM, Jordan Rose <jordan_rose@apple.com> >> wrote:
It's possible that @_transparent
<https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst> is
handled early enough in the compiler that we actually would get this
behavior. I'm not sure, though.+1 from me whether or not didSet is always called, though. "a = a ?? b"
always calls didSet anyway.Jordan
P.S. There's nothing particularly useful in the Radar, except that
together with the dups there are three suggested spellings: "=?", "?=", and
"??=". My vote is with Brent for "??=".On Dec 15, 2015, at 15:26 , James Campbell via swift-evolution < >>> swift-evolution@swift.org> wrote:
:) Wasn't expecting it to be trivial. but yeah if it could somehow be
short circuited so didSet, willSet isn't called when there is a value
already. that would be awesome.Could the willSet, didSet behaviour be tied to the = behaviour ? in
your example above the operation ultimately cascades into a = operation.Same with operations such as *= or /= ultimately it has to do a =
operation to set the new calculated value.On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch < >>> jtbandes@gmail.com> wrote:
I agree that would be nice. Just pointing out that it's nontrivial. If
you implement this custom operator today, you get different behavior.Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com> >>>> wrote:
If it has a value already the nit wouldn't call anything as it
technically hasn't been set. Only if it already has a value does it try and
set something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via >>>>> swift-evolution <swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs ==
nil { lhs = rhs() } }However, the use of "inout" will always cause the didSets to be
triggered at the call site, when just using if-statements instead wouldn't
have done so.Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via >>>>>> swift-evolution <swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need fairly
well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??`
operator more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698--
Wizard
james@supmenow.com
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698
--
Wizard
james@supmenow.com
+44 7523 279 698
Can you guys give me tips on how to improve this PR
Introduce a optional value setter `??=` by jcampbell05 · Pull Request #63 · apple/swift-evolution · GitHub first time writing a
proposal or anything to do with a language. Let me know if there are points
I missed.
On Wed, Dec 16, 2015 at 12:26 AM, James Campbell <james@supmenow.com> wrote:
On second thoughts, I'm preparing one :)
On Wed, Dec 16, 2015 at 12:24 AM, James Campbell <james@supmenow.com> > wrote:
Cool would be happy for you to do it :) if you time, almost night here
so :) but happy for you to quote me in the proposal.On Wed, Dec 16, 2015 at 12:17 AM, Jacob Bandes-Storch <jtbandes@gmail.com >> > wrote:
Would there be any caveats in introducing something like this, given the
raciness of the operator? I guess it's not really a big deal — the other
compound assignment operators (+=, -=, etc.) have the same problem.I'm not hearing much argument; sounds like many are in favor. I'd be
happy to flesh out my radar into a "??=" proposal this evening, or someone
else can do it if they'd like.Jacob
On Tue, Dec 15, 2015 at 4:12 PM, Jordan Rose <jordan_rose@apple.com> >>> wrote:
It's possible that @_transparent
<https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst> is
handled early enough in the compiler that we actually would get this
behavior. I'm not sure, though.+1 from me whether or not didSet is always called, though. "a = a ?? b"
always calls didSet anyway.Jordan
P.S. There's nothing particularly useful in the Radar, except that
together with the dups there are three suggested spellings: "=?", "?=", and
"??=". My vote is with Brent for "??=".On Dec 15, 2015, at 15:26 , James Campbell via swift-evolution < >>>> swift-evolution@swift.org> wrote:
:) Wasn't expecting it to be trivial. but yeah if it could somehow be
short circuited so didSet, willSet isn't called when there is a value
already. that would be awesome.Could the willSet, didSet behaviour be tied to the = behaviour ? in
your example above the operation ultimately cascades into a = operation.Same with operations such as *= or /= ultimately it has to do a =
operation to set the new calculated value.On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch < >>>> jtbandes@gmail.com> wrote:
I agree that would be nice. Just pointing out that it's nontrivial. If
you implement this custom operator today, you get different behavior.Jacob
On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <james@supmenow.com> >>>>> wrote:
If it has a value already the nit wouldn't call anything as it
technically hasn't been set. Only if it already has a value does it try and
set something in which case the didSet is called :)On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via >>>>>> swift-evolution <swift-evolution@swift.org> wrote:
One possible caveat is with custom setters.
If "a" already has a value, does "a ??= b" call the custom
setter/willSet/didSet, or does it see the nil and short-circuit?This can be implemented today:
func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs ==
nil { lhs = rhs() } }However, the use of "inout" will always cause the didSets to be
triggered at the call site, when just using if-statements instead wouldn't
have done so.Jacob
On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via >>>>>>> swift-evolution <swift-evolution@swift.org> wrote:
> I think that the existing syntax for “??” handles this need
fairly well without requiring an additional assignment operator:
>
> a = a ??When the variable is `a`, sure. When it’s
`scoreboardViewController.selectedScoreboard`, not so much.+1 from me, though I prefer the `??=` spelling to match the `??`
operator more closely.--
Brent Royal-Gordon
Architechies_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698--
Wizard
james@supmenow.com
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution--
Wizard
james@supmenow.com
+44 7523 279 698--
Wizard
james@supmenow.com
+44 7523 279 698
--
Wizard
james@supmenow.com
+44 7523 279 698