From: Raul Jara on
This doesn't work if you assign the strings to variables though:

'hi ' 'there'
=>"hi there"

hi = 'hi '
there = 'there'
hi there
NoMethodError: undefined method `hi' for main:Object
from (irb):9
from /opt/local/bin/irb:12:in `<main>'


Which is a little counter intuitive.
--
Posted via http://www.ruby-forum.com/.

From: Robert Klemme on
2010/2/19 Raul Jara <raul.c.jara(a)gmail.com>:
> This doesn't work if you assign the strings to variables though:
>
> 'hi ' 'there'
> =>"hi there"
>
> hi = 'hi '
> there = 'there'
> hi there
> NoMethodError: undefined method `hi' for main:Object
>  from (irb):9
>  from /opt/local/bin/irb:12:in `<main>'
>
>
> Which is a little counter intuitive.

Not for me. The concatenation is done at parse time. Your
"whitespace concatenation" is done at runtime.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

From: botp on
On Fri, Feb 19, 2010 at 10:07 PM, Robert Klemme
<shortcutter(a)googlemail.com> wrote:
> 2010/2/19 Raul Jara <raul.c.jara(a)gmail.com>:
>> This doesn't work if you assign the strings to variables though:
>>
>> 'hi ' 'there'
>> =>"hi there"
>>
>> hi = 'hi '
>> there = 'there'
>> hi there
>> NoMethodError: undefined method `hi' for main:Object
>>  from (irb):9
>>  from /opt/local/bin/irb:12:in `<main>'
>>
>>
>> Which is a little counter intuitive.
>
> Not for me.  The concatenation is done at parse time.  Your
> "whitespace concatenation" is done at runtime.

as long as it's quoted string literal,
try it like,

>> x="robert"
=> "robert"
>> y="raul"
=> "raul"
>> def m
>> "botp"
>> end
=> nil
>> "#{x}" \
?> "#{y}" "#{m}"
=> "robertraulbotp"

i think i remember a use case for this when i tried modifying a source
without using an editor, ...but i still have to search for that script
yet --if it's still on my newer disks...

best regards -botp

From: Raul Jara on
Robert Klemme wrote:
> 2010/2/19 Raul Jara <raul.c.jara(a)gmail.com>:
>> �from /opt/local/bin/irb:12:in `<main>'
>>
>>
>> Which is a little counter intuitive.
>
> Not for me. The concatenation is done at parse time. Your
> "whitespace concatenation" is done at runtime.
>
> Kind regards
>
> robert

I guess I find it counter intuitive to have such different behaviors
parse time vs. run time. If it isn't suppose to be a behavior of
strings that you can stick one next to another and have them
concatenate, then my brain has a hard time understanding why the parser
should treat them as though they do have that behavior?

--
Posted via http://www.ruby-forum.com/.

From: Robert Klemme on
On 19.02.2010 17:40, Raul Jara wrote:
> Robert Klemme wrote:
>> 2010/2/19 Raul Jara<raul.c.jara(a)gmail.com>:
>>> �from /opt/local/bin/irb:12:in `<main>'
>>>
>>>
>>> Which is a little counter intuitive.
>>
>> Not for me. The concatenation is done at parse time. Your
>> "whitespace concatenation" is done at runtime.
>
> I guess I find it counter intuitive to have such different behaviors
> parse time vs. run time.

Why? Parsing and executing are two fundamentally different things.

> If it isn't suppose to be a behavior of
> strings that you can stick one next to another and have them
> concatenate, then my brain has a hard time understanding why the parser
> should treat them as though they do have that behavior?

At least because of ambiguity: this line is a valid method invocation:

Robert(a)babelfish ~
$ ruby19 -ce 'foo bar'
Syntax OK

Robert(a)babelfish ~
$ ruby19 -e 'foo bar'
-e:1:in `<main>': undefined local variable or method `bar' for
main:Object (NameError)

Robert(a)babelfish ~
$

There is no way the parser can disambiguate concatenation of strings
referenced through variables and method invocations whereas a
concatenation of string literals is easily detectable.

Apart from that, I believe it is quite common in programming languages
to allow concatenation of string literals although that feature might be
rarely used.

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5
Prev: Help : Error in scrubyt
Next: DXF Writer?