https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-04-02T20:05:28ZRuby Issue Tracking SystemRuby master - Misc #15744: Improvement needed to documentation of 'Literals'https://redmine.ruby-lang.org/issues/15744?journal_id=774422019-04-02T20:05:28Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I am not sure if your definition can be used. For example, you refer to "compile time", but what is meant with<br>
compile time? As far as I know, ruby is not compiled in the sense of generating some binaries/binary executable,<br>
such as when you have a .c file and compile it via gcc; perhaps we can use the term compile differently<br>
(targeting the RubyVM and/or the JIT), but I think the term seems a bit misplaced when referring to literals.</p>
<p>The way I understand the documentation is that literals refers to most "entities" that you can find in a given<br>
.rb file, like, valid syntax components. The explanation "Literals create objects you can use in your program."<br>
probably refers to literals that can be used without any further ado, e. g. "abc" versus String.new("abc").</p>
<p>I guess your main point is a question as to whether a variable is a literal or not.</p>
<p>IF that is your question then I somewhat agree - the documentation could state whether a variable in itself<br>
is a literal. (I assume it is not because the value is not known upfront, unlike e. g. a number such as<br>
42). So the documentation could be changed to reflect this, if you refer to this.</p>
<p>I am not sure if I got all your comment - I think the ruby team is fine updating the documentation; just need<br>
to know what has to be changed/improved, possibly why, and to also ideally provide a way for text to be<br>
copy/pasted into it. :D</p>
<p>I don't know myself either but here is a start:</p>
<p>"Variables in ruby, such as x = 2 or y = '42', are not literals."</p>
<p>Or something like that, perhaps with a slightly longer explanation (I am guessing myself too).</p> Ruby master - Misc #15744: Improvement needed to documentation of 'Literals'https://redmine.ruby-lang.org/issues/15744?journal_id=774782019-04-05T00:22:05ZCaryInVictoria (Cary Swoveland)cary@swoveland.com
<ul></ul><p>shevegen (Robert A. Heiler) wrote:<br>
...I don't know myself either...</p>
<p>Robert,</p>
<p>I was only musing about a how a "literal" might be defined. My only point is that I think a definition is required, since the term is frequently used in discussing Ruby code. Alas, I don't think it's possible to define anything by example, and while I'm not convinced that a satisfactory definition is within reach, I believe it's worth a try.</p> Ruby master - Misc #15744: Improvement needed to documentation of 'Literals'https://redmine.ruby-lang.org/issues/15744?journal_id=788062019-06-24T02:27:28Zluke-gru (Luke Gruber)luke.gru@gmail.com
<ul></ul><p>IMO, literals are purely syntactic constructs. That doesn't mean they always behave the same as objects created by other means, ex: when calling methods, but as far as the definition of a literal, it's just a syntactic thing. Perhaps that could be mentioned in the docs, if people agree with that. I thought the docs made that fairly clear, going through all the syntax for different types of literals, but it could be more explicit.</p>
<p>Some object creation through literals does happen to behave differently though, ex: <code>"a literal string"</code> does not call <code>String.new</code> nor <code>String#initialize</code>, same for Arrays, Hashes, lambdas, etc... Perhaps this could be mentioned, but it's probably too much information, and would complicate a document that seems to be aimed at Ruby beginners. Also, string literals can be created frozen with the magic comment, but that's just an optimization.</p>
<p>As for whether variables are literals, no I don't think so. Variables can be referred to in a literal, ex in <code>[a,b,c,d]</code> the array is a literal, but the variables aren't themselves literals.</p>
<p>As for whether literals must be able to be embedded into ruby bytecode to be considered literals, I disagree. This is just an optimization that can be done with some literals.</p>
<p>Do others think this document needs clarification?</p>