Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #27096 > unrolled thread
| Started by | markspace <markspace@nospam.nospam> |
|---|---|
| First post | 2013-12-28 08:59 -0800 |
| Last post | 2013-12-28 16:36 -0500 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: literals and keywords markspace <markspace@nospam.nospam> - 2013-12-28 08:59 -0800
Re: literals and keywords "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-12-28 17:28 +0000
Re: literals and keywords markspace <markspace@nospam.nospam> - 2013-12-28 10:56 -0800
Re: literals and keywords Arne Vajhøj <arne@vajhoej.dk> - 2013-12-28 14:53 -0500
Re: literals and keywords markspace <markspace@nospam.nospam> - 2013-12-28 12:41 -0800
Re: literals and keywords Arne Vajhøj <arne@vajhoej.dk> - 2013-12-28 16:36 -0500
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2013-12-28 08:59 -0800 |
| Subject | Re: literals and keywords |
| Message-ID | <l9n026$7to$1@dont-email.me> |
On 12/28/2013 8:15 AM, Stefan Ram wrote: > Does it matter? > > Can you find any program, where one can observe the difference? > E.g., some program that does compile because they are not keywords, > but would not compile when they were keywords, or vice versa? > Or are there any other observable consequences of this difference? > Yes, it matters, or they wouldn't make a distinction. We talked about this already: literals can be used in expressions, keywords can't. The observable difference is in the implementation of the JLS. <http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.8> You can write "int i = 1 + 2;" but you can't write "Object o = for + try;" because that section of the JLS says so. Read it.
[toc] | [next] | [standalone]
| From | "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> |
|---|---|
| Date | 2013-12-28 17:28 +0000 |
| Message-ID | <hqGdnX-5w61DlyLPnZ2dnUVZ7sednZ2d@bt.com> |
| In reply to | #27096 |
Stefan Ram wrote:
> Just as
> the keyword »this« names a value, the keyword »true« would
> name a value. So, when they have decided to call »this« a
> keyword, but not »true«, does it matter? Is there any point
> where it helps to know that »this« is a keyword, but »true«
> is not?
I think the distinction is of more use to compiler (and other tool) creators[*]
than to common-or-garden programmers.
The same can be said of the whole of the spec.
-- chris
[*] And, of course, to pedant-class language specialists.
[toc] | [prev] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2013-12-28 10:56 -0800 |
| Message-ID | <l9n6tq$fsh$1@dont-email.me> |
| In reply to | #27096 |
On 12/28/2013 9:17 AM, Stefan Ram wrote: > markspace <markspace@nospam.nospam> writes: >> this already: literals can be used in expressions, keywords can't. > > It is not true that keywords can't be used in expressions, > for example, the expression »this« contains the keyword »this«. > Yes, and there are two other keywords mentioned in that section that get used in expressions, if you read it. > Keywords can introduce statements, as in the case of »if«, This is rather untrue. if takes an expression as an argument because the spec says there must be an expression there. These things aren't founded out some inherent principle of ur-computing, they're arbitrarily dictated by the the spec. That's it. > or they can name types, as in the case of »int«, or "int" when it introduces an expression is called a "declaration", not an expression. "(int)" as a cast is a special type of expression. Both of those constructs are dictatated by the spec. > references as in the case of »this«. It would have been > possible to make »true« a keyword in Java as well. Just as But it doesn't make sense. When you look at discreet math, the concept of a literal value is already present. "true" and "false" are the literal values that boolean values can have in mathematics. When the spec says that true and false are literals, it's trying to mimic the natural language way of expressing that concept, what already exists in the math. What you seem to be saying to me is contorted and unnatural. Just read that part of the spec the way it's written, and understand it naturally. Why exactly "this" and "new" and "super" aren't literals, I don't know. Possibly because their value isn't fixed, but depends on context, and therefore isn't actually a single literal value. They represent a range of values, and the language implementers didn't want to call them operators or variables or introduce a new concept like "special function," so they just called them a keyword because they had the concept already and it worked well enough.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-12-28 14:53 -0500 |
| Message-ID | <52bf2c49$0$304$14726298@news.sunsite.dk> |
| In reply to | #27100 |
On 12/28/2013 1:56 PM, markspace wrote: > Why exactly "this" and "new" and "super" aren't literals, I don't know. > Possibly because their value isn't fixed, but depends on context, and > therefore isn't actually a single literal value. They represent a range > of values, and the language implementers didn't want to call them > operators or variables or introduce a new concept like "special > function," so they just called them a keyword because they had the > concept already and it worked well enough. this and super are not constant so they could never be called a literal. And new is an operator. More like instanceof. Arne
[toc] | [prev] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2013-12-28 12:41 -0800 |
| Message-ID | <l9nd1t$jhs$1@dont-email.me> |
| In reply to | #27101 |
On 12/28/2013 11:53 AM, Arne Vajhøj wrote: > And new is an operator. Is it? That section I linked to refers to "new" as a keyword. <http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.9> Five paragraphs after that link. "...the type arguments to the constructor immediately follow the keyword _new_." And a couple of other places too.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-12-28 16:36 -0500 |
| Message-ID | <52bf446c$0$301$14726298@news.sunsite.dk> |
| In reply to | #27102 |
On 12/28/2013 3:41 PM, markspace wrote: > On 12/28/2013 11:53 AM, Arne Vajhøj wrote: > >> And new is an operator. > > Is it? That section I linked to refers to "new" as a keyword. > > <http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.9> > > Five paragraphs after that link. > > "...the type arguments to the constructor immediately follow the keyword > _new_." > > And a couple of other places too. Operators that are words and not special characters are also keywords. But a quick check reveals that you are absolutely right - JLS do not call new an operator even though it does call instanceof an operator. That surprises me. In C++ and C# new is considered an operator. And I do not seem to be the only one surprised. The Java tutorial actually call it an operator. Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web