rfc:arbitrary_string_interpolation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:arbitrary_string_interpolation [2022/03/17 19:27] ilutovrfc:arbitrary_string_interpolation [2022/03/27 16:17] – Add comparison to other languages ilutov
Line 3: Line 3:
   * Date: 2022-03-17   * Date: 2022-03-17
   * Author: Ilija Tovilo, tovilo.ilija@gmail.com   * Author: Ilija Tovilo, tovilo.ilija@gmail.com
-  * Status: Draft+  * Status: Under discussion
   * Target Version: PHP 8.2   * Target Version: PHP 8.2
-  * Implementation: https://github.com/php/php-src/compare/master...iluuu1994:arbitrary-string-interpolation+  * Implementation: https://github.com/php/php-src/pull/8256
  
 ===== Proposal ===== ===== Proposal =====
Line 38: Line 38:
 </code> </code>
  
-The proposed syntax works in double quoted strings (''""''), heredoc (<<<TXT TXT) and the execution operator (''``'').+The proposed syntax works in all cases where existing string interpolation is allowed, namely double quoted strings (''""''), heredoc (''<<<TXT TXT'') and the execution operator (''``'').
  
 ===== Motivation ===== ===== Motivation =====
Line 103: Line 103:
  
 None None
 +
 +===== Comparison to other languages =====
 +
 +Most modern languages have string interpolation that allow arbitrary expressions.
 +
 +^ Language                                                                                           ^ Syntax                        ^
 +| [[https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated|C#]]       | ''$"x + y = {x + y}"''        |
 +| [[https://api.dart.dev/stable/2.16.1/dart-core/String-class.html|Dart]]                            | '''x + y = ${x + y}'''        |
 +| [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals|JavaScript]] | ''`x + y = ${x + y}`''        |
 +| [[https://kotlinlang.org/docs/basic-types.html#string-templates|Kotlin]]                           | ''"x + y = ${x + y}"''        |
 +| [[https://peps.python.org/pep-0498/|Python]]                                                       | ''f'x + y = {x + y}'''        |
 +| [[https://docs.raku.org/language/quoting.html#Interpolation:_qq|Raku (Perl6)]]                     | ''"\$x + \$y = { $x + $y }"'' |
 +| [[http://ruby-for-beginners.rubymonstas.org/bonus/string_interpolation.html|Ruby]]                 | ''"x + y = #{x + y}"''        |
 +| [[https://docs.scala-lang.org/overviews/core/string-interpolation.html|Scala]]                     | ''s"x + y = ${$x + $y}"''     |
 +| [[https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html#ID292|Swift]]          | ''"x + y = \(x + y)"''        |
  
 ===== Credits ===== ===== Credits =====
  
-Credits to Rowan Tommins (IMSoP) for the syntax suggestion.+Credits to Rowan Tommins (IMSoP) for the syntax suggestion and comparison to other languges.
  
 ===== Vote ===== ===== Vote =====
rfc/arbitrary_string_interpolation.txt · Last modified: 2022/06/25 21:47 by ilutov