Proposal: Embedded Expressions for String Statements
John Rose
John.Rose at Sun.COM
Fri Mar 20 13:50:05 PDT 2009
I wrote the spec. draft and implementation (in antlr) for Groovy
gstring syntax; I did the work with the intention of helping the JSR
241 Groovy standard. It could work in Java with adjustments, and the
Groovy spec. is detailed enough to be a starting point. I don't
really have time to work on it though. That's why I haven't done a
proposal.
For Java, to extend the string syntax and emphasize that a new string
is being constructed, I recommend this:
new "$foo, ${bar}s."
The new kwd enables the dollars. Other details to be taken from the
Groovy spec.
Best wishes,
-- John (on my iPhone)
On Mar 19, 2009, at 8:33 AM, phil swenson <phil.swenson at gmail.com>
wrote:
> funny, i just joined the list specifically to ask about this subject.
>
> why not just copy the groovy implementation of this? $var or $
> {expresion} ?
> in groovy it would be:
> "[$field1, $field2, $field3]"
>
> or with the explicit expression syntax:
> "[${field1}, ${field2}, ${field3}]"
>
>
> I hate escape characters :)
>
>
> On Thu, Mar 19, 2009 at 2:03 AM, Schulz, Stefan <schulz at e-spirit.de>
> wrote:
>> The concat-variant to me is even worse readable than the original +-
>> notation, having three consecutive commas in between.
>> The proposal already mentions concatenation of any kind as
>> alternative, although not mentioning concat(). Maybe worth expanding.
>>
>> Stefan
>>
>>> -----Original Message-----
>>> From: rssh at gradsoft.com.ua [mailto:rssh at gradsoft.com.ua]
>>> Sent: Wednesday, March 18, 2009 8:58 PM
>>> To: Howard Lovatt
>>> Cc: coin-dev at openjdk.java.net; Schulz, Stefan
>>> Subject: Re: Proposal: Embedded Expressions for String Statements
>>>
>>>> I like Stefan's proposed syntax and as a way of a motivating
>>>> example
>>>> consider writing a toString method that gives the field
>>> values within
>>>> square brackets, now you would write:
>>>>
>>>> "[" + field1 + ", " + field2 + ", " + field3 + "]"
>>>>
>>>> With the proposal you would say:
>>>>
>>>> "[\{field1}, \{field2}, \{field3}]"
>>>>
>>>> Which I find clearer.
>>>>
>>>
>>> Just note: now we can use much cleaner
>>> concat( field1, ',' , field2, ',' field3 )
>>>
>>>
>>>
>>>> Many thanks to Stefan for writing this up formally.
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>>
>
More information about the coin-dev
mailing list