[Idea] Trailing Multi-Line String Literal


(Gor Gyolchanyan) #1

Good day, swift evolution community!

I'll just get right to it...

Did anyone else beside me wished this was a thing?

func parse(allowSomeBehavior: Bool = true, source: String) {
  // ...
}

parse(allowSomeBehavior: false) """
  This is a source string
  that contains a number of lines of text
  which is passed to the function `parse`
  """

parse """
  The exact same thing as above
  except no other parameters are specified
  """


(David Hart) #2

Personally, I have never felt that need.

Trailing closures fill of need of making Swift a good candidate for building DSLs, where they make the function calls look more like first-class operations. But I don’t think that trailing strings would be as useful.

David.

···

On 15 Jun 2017, at 11:54, Gor Gyolchanyan via swift-evolution <swift-evolution@swift.org> wrote:

Good day, swift evolution community!

I'll just get right to it...

Did anyone else beside me wished this was a thing?

func parse(allowSomeBehavior: Bool = true, source: String) {
  // ...
}

parse(allowSomeBehavior: false) """
  This is a source string
  that contains a number of lines of text
  which is passed to the function `parse`
  """

parse """
  The exact same thing as above
  except no other parameters are specified
  """

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


(Gor Gyolchanyan) #3

Funny you should mention DSLs:

let myQuery = sql """
  SELECT id, name, date
  FROM MyTable
  WHERE id > 100
  """

let myLayout = NSLayoutConstraint """
  ...
  """

let myPredicate = NSPredicate ""
  ...
  """

···

On Jun 15, 2017, at 2:05 PM, David Hart <davidhart@fastmail.com> wrote:

Personally, I have never felt that need.

Trailing closures fill of need of making Swift a good candidate for building DSLs, where they make the function calls look more like first-class operations. But I don’t think that trailing strings would be as useful.

David.

On 15 Jun 2017, at 11:54, Gor Gyolchanyan via swift-evolution <swift-evolution@swift.org> wrote:

Good day, swift evolution community!

I'll just get right to it...

Did anyone else beside me wished this was a thing?

func parse(allowSomeBehavior: Bool = true, source: String) {
  // ...
}

parse(allowSomeBehavior: false) """
  This is a source string
  that contains a number of lines of text
  which is passed to the function `parse`
  """

parse """
  The exact same thing as above
  except no other parameters are specified
  """

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


(David Hart) #4

I totally see what you are driving at. But I just see less value in it that with trailing closure. But it’s very personal.

···

On 15 Jun 2017, at 13:18, Gor Gyolchanyan <gor@gyolchanyan.com> wrote:

Funny you should mention DSLs:

let myQuery = sql """
  SELECT id, name, date
  FROM MyTable
  WHERE id > 100
  """

let myLayout = NSLayoutConstraint """
  ...
  """

let myPredicate = NSPredicate ""
  ...
  """

On Jun 15, 2017, at 2:05 PM, David Hart <davidhart@fastmail.com> wrote:

Personally, I have never felt that need.

Trailing closures fill of need of making Swift a good candidate for building DSLs, where they make the function calls look more like first-class operations. But I don’t think that trailing strings would be as useful.

David.

On 15 Jun 2017, at 11:54, Gor Gyolchanyan via swift-evolution <swift-evolution@swift.org> wrote:

Good day, swift evolution community!

I'll just get right to it...

Did anyone else beside me wished this was a thing?

func parse(allowSomeBehavior: Bool = true, source: String) {
  // ...
}

parse(allowSomeBehavior: false) """
  This is a source string
  that contains a number of lines of text
  which is passed to the function `parse`
  """

parse """
  The exact same thing as above
  except no other parameters are specified
  """

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


(Xiaodi Wu) #5

Agree with David on all points. Neat idea, but not convinced it’s a win in
terms of tidying up code vs. increased burden of new grammar rule.

Agree also that it’s a subjective opinion. For me, ({[]}) nesting is clunky
both to read and write, but (“”) just doesn’t have the same issues even
with multiline syntax–the symbols are just so unlike each other.

Your DSL examples, if truly you’re using them often, suggest that these
particular types should be extended to conform to
ExpressibleByStringLiteral.

···

On Thu, Jun 15, 2017 at 11:16 David Hart via swift-evolution < swift-evolution@swift.org> wrote:

I totally see what you are driving at. But I just see less value in it
that with trailing closure. But it’s very personal.

> On 15 Jun 2017, at 13:18, Gor Gyolchanyan <gor@gyolchanyan.com> wrote:
>
> Funny you should mention DSLs:
>
> let myQuery = sql """
> SELECT id, name, date
> FROM MyTable
> WHERE id > 100
> """
>
> let myLayout = NSLayoutConstraint """
> ...
> """
>
> let myPredicate = NSPredicate ""
> ...
> """
>
>> On Jun 15, 2017, at 2:05 PM, David Hart <davidhart@fastmail.com> wrote:
>>
>> Personally, I have never felt that need.
>>
>> Trailing closures fill of need of making Swift a good candidate for
building DSLs, where they make the function calls look more like
first-class operations. But I don’t think that trailing strings would be as
useful.
>>
>> David.
>>
>>> On 15 Jun 2017, at 11:54, Gor Gyolchanyan via swift-evolution < > swift-evolution@swift.org> wrote:
>>>
>>> Good day, swift evolution community!
>>>
>>> I'll just get right to it...
>>>
>>> Did anyone else beside me wished this was a thing?
>>>
>>> func parse(allowSomeBehavior: Bool = true, source: String) {
>>> // ...
>>> }
>>>
>>> parse(allowSomeBehavior: false) """
>>> This is a source string
>>> that contains a number of lines of text
>>> which is passed to the function `parse`
>>> """
>>>
>>> parse """
>>> The exact same thing as above
>>> except no other parameters are specified
>>> """
>>>
>>> _______________________________________________
>>> 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


(Gor Gyolchanyan) #6

I agree that nested braces in parentheses are much more ugly then nested quotes in parentheses.
About ExressibleByStringLiteral: This is a completely orthogonal case. The issue is passing these string literals to functions.
The passed literal doesn't have to be string, it can be any other ExpressibleByStringLiteral.
This is not something that I'd like to actively push for because this really is not that big of a deal, but some case that happened to me a couple of times and given that the exact same behavior is already implemented with closures, I though extending it to encompass string literal would be a cheap way of making another popular use case easier on the eye.

···

On Jun 15, 2017, at 7:49 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

Agree with David on all points. Neat idea, but not convinced it’s a win in terms of tidying up code vs. increased burden of new grammar rule.

Agree also that it’s a subjective opinion. For me, ({[]}) nesting is clunky both to read and write, but (“”) just doesn’t have the same issues even with multiline syntax–the symbols are just so unlike each other.

Your DSL examples, if truly you’re using them often, suggest that these particular types should be extended to conform to ExpressibleByStringLiteral.
On Thu, Jun 15, 2017 at 11:16 David Hart via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
I totally see what you are driving at. But I just see less value in it that with trailing closure. But it’s very personal.

> On 15 Jun 2017, at 13:18, Gor Gyolchanyan <gor@gyolchanyan.com <mailto:gor@gyolchanyan.com>> wrote:
>
> Funny you should mention DSLs:
>
> let myQuery = sql """
> SELECT id, name, date
> FROM MyTable
> WHERE id > 100
> """
>
> let myLayout = NSLayoutConstraint """
> ...
> """
>
> let myPredicate = NSPredicate ""
> ...
> """
>
>> On Jun 15, 2017, at 2:05 PM, David Hart <davidhart@fastmail.com <mailto:davidhart@fastmail.com>> wrote:
>>
>> Personally, I have never felt that need.
>>
>> Trailing closures fill of need of making Swift a good candidate for building DSLs, where they make the function calls look more like first-class operations. But I don’t think that trailing strings would be as useful.
>>
>> David.
>>
>>> On 15 Jun 2017, at 11:54, Gor Gyolchanyan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>>>
>>> Good day, swift evolution community!
>>>
>>> I'll just get right to it...
>>>
>>> Did anyone else beside me wished this was a thing?
>>>
>>> func parse(allowSomeBehavior: Bool = true, source: String) {
>>> // ...
>>> }
>>>
>>> parse(allowSomeBehavior: false) """
>>> This is a source string
>>> that contains a number of lines of text
>>> which is passed to the function `parse`
>>> """
>>>
>>> parse """
>>> The exact same thing as above
>>> except no other parameters are specified
>>> """
>>>
>>> _______________________________________________
>>> 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