[erlang-questions] String continuation

Ulf Wiger ulf.wiger@REDACTED
Thu Jan 13 22:47:55 CET 2011


Actually, and you can verify this with erlc -S, they are _all_ the same,
as Robert said:

f() -> "a" "b".

g() -> "ab".

h() -> "a" ++ "b".

compiles to:

{function, f, 0, 2}.
  {label,1}.
    {func_info,{atom,strs},{atom,f},0}.
  {label,2}.
    {move,{literal,"ab"},{x,0}}.
    return.

{function, g, 0, 4}.
  {label,3}.
    {func_info,{atom,strs},{atom,g},0}.
  {label,4}.
    {move,{literal,"ab"},{x,0}}.
    return.

{function, h, 0, 6}.
  {label,5}.
    {func_info,{atom,strs},{atom,h},0}.
  {label,6}.
    {move,{literal,"ab"},{x,0}}.
    return.

BR,
Ulf W

On 13 Jan 2011, at 23:23, Mazen Harake wrote:

> I think you are confusing the two. Writing two strings without anything in between is a literal and not a statement of concatenation of both. This means that:
> 
> f() -> "Hello" "World".
> 
> is the same as...
> 
> f() -> "HelloWorld".
> 
> and not
> 
> f() -> "Hello" ++ "World".
> 
> 
> /Mazen
> 
> On 13/01/2011 18:40, Attila Rajmund Nohl wrote:
>> Hello!
>> 
>> Let's have a look at this little example code:
>> 
>> -module('strc').
>> 
>> -export([f/0]).
>> 
>> f() ->
>>     {["string1",
>>       "string2"],
>>      ["string3"
>>       "string4"]}.
>> 
>> This compiles fine and returns a tuple with two lists, the first with
>> 2 strings, the second with a single list. Of course, if there was only
>> a typo in the second list (a missed comma), I wouldn't notice it until
>> the code executes (which might happen in an inconvenient time in error
>> handling code). I wonder that the possibility to omit the extra ++
>> from the end of "string3" line worth the problems what might be caused
>> by the missing comma. This only bit me once, so it might not be that
>> common...
>> 
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>> 
> 
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
> 

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com





More information about the erlang-questions mailing list