https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-07-04T06:23:30ZRuby Issue Tracking SystemRuby master - Feature #15983: Can we have a similar syntax (string interpolation) the way V language has?https://redmine.ruby-lang.org/issues/15983?journal_id=790902019-07-04T06:23:30Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>There are other languages that use $ in string interpolation. One of them is Perl. Perl is much more famous and widely used than V. Ruby was created as a better Perl. $variable_name may work (most of the time, but not always) in languages with spaces between words, but it doesn't work well in a language that's written without spaces, such as Japanese. My guess is that this is one of the reasons for why Matz choose an explicit terminator ('}') for interpolations.</p> Ruby master - Feature #15983: Can we have a similar syntax (string interpolation) the way V language has?https://redmine.ruby-lang.org/issues/15983?journal_id=790962019-07-04T07:45:39Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>Let's look at this purely from a syntax point of view first, so that we can avoid<br>
other issues such as backwards incompatible changes (which may be a big reason<br>
why this request will not be implemented; but you have to ask matz).</p>
<p>I think you have made a good point that e. g.</p>
<pre><code>$foo = 'world'
puts "hello $foo"
</code></pre>
<p>would be simpler to type than e. g.</p>
<pre><code>puts "hello #{$foo}"
</code></pre>
<p>or</p>
<pre><code>foo = 'world'
puts "hello #{foo}"
</code></pre>
<p>Actually, for global variables this is already possible and has been<br>
for many years; for @instance_variables this also seems to work... I<br>
thought it would not work but I just tested this:</p>
<pre><code>@foo = 'world'
puts "hello #@foo"
</code></pre>
<p>And that works.</p>
<p>Martin pointed out that Perl allows for string interpolation like that,<br>
although it still seems different to this behaviour:</p>
<pre><code>areas := ['game', 'web', 'tools']
for area in areas {
println('Hello, $area developers!')
</code></pre>
<p>Since we do not need special access modifiers for the variable "areas",<br>
whereas I seem to remember in perl we had to use some identifier<br>
such as $areas or something like that; or @areas or something (it<br>
has been literally like almost +15 years since I last wrote perl<br>
code ...).</p>
<p>Having said that, I think that it is probably not easily doable to<br>
interpolate without #{} for non-global variables, as otherwise<br>
it might have been done yet.</p>
<p>Adding another syntax identifier as proposed, would, in my opinion,<br>
not be a good idea, since the scope of the change is motivated<br>
primarily by the possibility to avoid #{} only. #{} can be annoying,<br>
but having to add a new character solely for this would be bad as<br>
well, I think. Then there is also the issue of backwards compatibility,<br>
so I think while it is an interesting idea, it is most likely not<br>
a very realistic one. But that is just my opinion - ultimately you<br>
have to ask matz. :)</p> Ruby master - Feature #15983: Can we have a similar syntax (string interpolation) the way V language has?https://redmine.ruby-lang.org/issues/15983?journal_id=802332019-07-30T03:41:03Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><blockquote>
<p>I know that Ruby has already occupied this $ character. But we can use another character which is not used in Ruby.</p>
</blockquote>
<p>Please make new ticket if you have good character instead of <code>$</code>.</p>
<p>Thanks.</p>