Should we incorporate bunches of new operators / micro-syntactic sugar?

Dear all,

That’s not ambitious but i think worth be explored.

What do you think for example of this Infix operator?
« =? » allows to express optional assignments in a very concise way.

// The `=? operator allows simplify optional assignements :
// `a = b ?? a` can be written : `a =? b`
infix operator =?: AssignmentPrecedence

public func =?<T> ( left:inout T?, right: T? ){
    left = right ?? left
}

public func =?<T> ( left:inout T, right: T? ){
    left = right ?? left
}

Do you have such operators that you really use very often?

Best regards

Benoit

Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com <https://pereira-da-silva.com/>

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.

Such an operator was proposed here: https://github.com/apple/swift-evolution/blob/60a8980a66a0a1341871ec323797c5547d0e0925/proposals/0024-optional-value-setter.md

It was ultimately rejected: https://lists.swift.org/pipermail/swift-evolution-announce/2016-February/000043.html

Stephen

···

On Dec 21, 2017, at 11:44 AM, Benoit Pereira da silva via swift-evolution <swift-evolution@swift.org> wrote:

Dear all,

That’s not ambitious but i think worth be explored.

What do you think for example of this Infix operator?
« =? » allows to express optional assignments in a very concise way.

// The `=? operator allows simplify optional assignements :
// `a = b ?? a` can be written : `a =? b`
infix operator =?: AssignmentPrecedence

public func =?<T> ( left:inout T?, right: T? ){
    left = right ?? left
}

public func =?<T> ( left:inout T, right: T? ){
    left = right ?? left
}

Do you have such operators that you really use very often?

Best regards

Benoit

Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com <https://pereira-da-silva.com/>

<bannerp.jpg>

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Stephen,

You are right the proposal #0024 is very close.
But in fact the logic is inverted.

When using «=? » the right item is optional.
a =? b assigns « b » to « a » only if « b » is defined.
So if an optional is defined =? will not erase its value.

But my real questions was…
Do you have such operators that you really use very often?
Should we incorporate bunches of new operators / micro-syntactic sugar?
Is swift evolution the good place to discuss such question?

I don’t want to pollute your mail boxes.

Best regards,

B

Such an operator was proposed here: https://github.com/apple/swift-evolution/blob/60a8980a66a0a1341871ec323797c5547d0e0925/proposals/0024-optional-value-setter.md

It was ultimately rejected: https://lists.swift.org/pipermail/swift-evolution-announce/2016-February/000043.html

Stephen

Dear all,

That’s not ambitious but i think worth be explored.

What do you think for example of this Infix operator?
« =? » allows to express optional assignments in a very concise way.

// The `=? operator allows simplify optional assignements :
// `a = b ?? a` can be written : `a =? b`
infix operator =?: AssignmentPrecedence

public func =?<T> ( left:inout T?, right: T? ){
    left = right ?? left
}

public func =?<T> ( left:inout T, right: T? ){
    left = right ?? left
}

Do you have such operators that you really use very often?

Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com <https://pereira-da-silva.com/>

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.

···

Le 21 déc. 2017 à 19:12, Stephen Celis <stephen.celis@gmail.com> a écrit :

On Dec 21, 2017, at 11:44 AM, Benoit Pereira da silva via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

possibly off-topic but what i would really find useful is some way of
expressing guard/if assignment instead of initialization so that

        let geomSource:UnsafeMutableBufferPointer<CChar>?
        if let geometryFile:String = geometryFile
        {
            guard let _geomSource:UnsafeMutableBufferPointer<CChar> =
                Shader.openTextFile(Shader.posixPath(geometryFile))
            else
            {
                return nil
            }

            geomSource = _geomSource
        }

could be rewritten as

        let geomSource:UnsafeMutableBufferPointer<CChar>?
        if let geometryFile:String = geometryFile
        {
            guard geomSource:UnsafeMutableBufferPointer<CChar> =
                Shader.openTextFile(Shader.posixPath(geometryFile))
            else
            {
                return nil
            }
        }

···

On Thu, Dec 21, 2017 at 1:00 PM, Stephen Celis via swift-evolution < swift-evolution@swift.org> wrote:

Ah, sorry, I misread! For readability I think I'd still favor something
like:

    if let b = b {
      dict[a] = b
    }

And I think some the arguments made in #0024 may still apply here, though
feel free to discuss!

Stephen

On Dec 21, 2017, at 1:37 PM, Benoit Pereira da silva <bpds@me.com> wrote:

Stephen,

You are right the proposal #0024 is very close.
But in fact the logic is inverted.

When using «=? » the right item is optional.
a =? b assigns « b » to « a » only if « b » is defined.
So if an optional is defined =? will not erase its value.

But my real questions was…
Do you have such operators that you really use very often?
Should we incorporate bunches of new operators / micro-syntactic sugar?
Is swift evolution the good place to discuss such question?

I don’t want to pollute your mail boxes.

Best regards,

B

Le 21 déc. 2017 à 19:12, Stephen Celis <stephen.celis@gmail.com> a écrit :

Such an operator was proposed here: https://github.com/
apple/swift-evolution/blob/60a8980a66a0a1341871ec323797c5
547d0e0925/proposals/0024-optional-value-setter.md

It was ultimately rejected: https://lists.swift.
org/pipermail/swift-evolution-announce/2016-February/000043.html

Stephen

On Dec 21, 2017, at 11:44 AM, Benoit Pereira da silva via swift-evolution < > swift-evolution@swift.org> wrote:

Dear all,

That’s not ambitious but i think worth be explored.

What do you think for example of this Infix operator?
« =? » allows to express optional assignments in a very concise way.

// The `=? operator allows simplify optional assignements :
// `a = b ?? a` can be written : `a =? b`
infix operator =?: AssignmentPrecedence

public func =?<T> ( left:inout T?, right: T? ){
    left = right ?? left
}

public func =?<T> ( left:inout T, right: T? ){
    left = right ?? left
}

Do you have such operators that you really use very often?

*Benoit Pereira da Silva*
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com

<bannerp.jpg>

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of
this information for any purpose is prohibited without agreement of the
sender.
Ce message est confidentiel. Toute distribution, copie, publication ou
usage des informations contenues dans ce message sont interdits sans
agrément préalable de l'expéditeur.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Ah, sorry, I misread! For readability I think I'd still favor something like:

    if let b = b {
      dict[a] = b
    }

And I think some the arguments made in #0024 may still apply here, though feel free to discuss!

Stephen

···

On Dec 21, 2017, at 1:37 PM, Benoit Pereira da silva <bpds@me.com> wrote:

Stephen,

You are right the proposal #0024 is very close.
But in fact the logic is inverted.

When using «=? » the right item is optional.
a =? b assigns « b » to « a » only if « b » is defined.
So if an optional is defined =? will not erase its value.

But my real questions was…
Do you have such operators that you really use very often?
Should we incorporate bunches of new operators / micro-syntactic sugar?
Is swift evolution the good place to discuss such question?

I don’t want to pollute your mail boxes.

Best regards,

B

Le 21 déc. 2017 à 19:12, Stephen Celis <stephen.celis@gmail.com <mailto:stephen.celis@gmail.com>> a écrit :

Such an operator was proposed here: https://github.com/apple/swift-evolution/blob/60a8980a66a0a1341871ec323797c5547d0e0925/proposals/0024-optional-value-setter.md

It was ultimately rejected: https://lists.swift.org/pipermail/swift-evolution-announce/2016-February/000043.html

Stephen

On Dec 21, 2017, at 11:44 AM, Benoit Pereira da silva via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Dear all,

That’s not ambitious but i think worth be explored.

What do you think for example of this Infix operator?
« =? » allows to express optional assignments in a very concise way.

// The `=? operator allows simplify optional assignements :
// `a = b ?? a` can be written : `a =? b`
infix operator =?: AssignmentPrecedence

public func =?<T> ( left:inout T?, right: T? ){
    left = right ?? left
}

public func =?<T> ( left:inout T, right: T? ){
    left = right ?? left
}

Do you have such operators that you really use very often?

Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com <https://pereira-da-silva.com/>

<bannerp.jpg>

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.

To answer your meta question, no, we don’t want to add lots of operators. We are willing to add them if they are very strongly motivated, but prefer not to if there are other ways to solve the problem.

In this case it sounds like:

   x = optionalValue ?? x

Is a reasonable substitute.

-Chris

···

On Dec 21, 2017, at 10:38 AM, Benoit Pereira da silva via swift-evolution <swift-evolution@swift.org> wrote:

Stephen,

You are right the proposal #0024 is very close.
But in fact the logic is inverted.

When using «=? » the right item is optional.
a =? b assigns « b » to « a » only if « b » is defined.
So if an optional is defined =? will not erase its value.

But my real questions was…
Do you have such operators that you really use very often?
Should we incorporate bunches of new operators / micro-syntactic sugar?
Is swift evolution the good place to discuss such question?

I don’t want to pollute your mail boxes.

Best regards,

B

Le 21 déc. 2017 à 19:12, Stephen Celis <stephen.celis@gmail.com> a écrit :

Such an operator was proposed here: https://github.com/apple/swift-evolution/blob/60a8980a66a0a1341871ec323797c5547d0e0925/proposals/0024-optional-value-setter.md

It was ultimately rejected: https://lists.swift.org/pipermail/swift-evolution-announce/2016-February/000043.html

Stephen

On Dec 21, 2017, at 11:44 AM, Benoit Pereira da silva via swift-evolution <swift-evolution@swift.org> wrote:

Dear all,

That’s not ambitious but i think worth be explored.

What do you think for example of this Infix operator?
« =? » allows to express optional assignments in a very concise way.

// The `=? operator allows simplify optional assignements :
// `a = b ?? a` can be written : `a =? b`
infix operator =?: AssignmentPrecedence

public func =?<T> ( left:inout T?, right: T? ){
    left = right ?? left
}

public func =?<T> ( left:inout T, right: T? ){
    left = right ?? left
}

Do you have such operators that you really use very often?

Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution