> There are languages that disallow multiline string literals entirely. 
> Among languages that allow multiline string literals (including Ruby and 
> Python with """ and Perl with here documents), there seem to be none that 
> do what you're suggesting. The fact that no languages seem to do what you 
> suggest, indicates that there's not a lot of people – at least among those 
> who design languages – who think it's an intuitive behavior. 
>

Agreed
 

> Why would you think that you can just put random newlines into string 
> literals and have them be ignored?
>

Maybe for the same reason (and admittedly idiot example) that we can do

julia> for (k = 1
       :3)
       println(k)
       end
1
2
3
 

> Other characters aren't ignored in string literals.
>

but they are not invisible ones, are they? 



 

>
> On Thu, Aug 27, 2015 at 1:44 PM, J Luis <[email protected] <javascript:>> 
> wrote:
>
>>
>> Can you give an example of any language where that's how it works?
>>>
>>
>> No. The only other dynamic language I know is Matlab and it does not even 
>> allow creating a string in multiple lines without concatenation ([]).
>> But I guess the point here is what is intended when writing over multiple 
>> lines.
>> If the intention is really to create a multiple line string than the 
>> current behavior is right. However, if the intention is to use the break as 
>> an implicit line continuation (as was my intention, and others before me) 
>> than the current behavior is at least surprising.
>>
>> Since both uses are licit, the clearer solution would be that intended \n 
>> should be written explicitly.
>>  
>>
>>>
>>> On Thu, Aug 27, 2015 at 11:26 AM, J Luis <[email protected]> wrote:
>>>
>>>> I understand that's how it works, but I'm not convinced that is how it 
>>>> should work. For me the newline character should be included only when 
>>>> user 
>>>> requested so, as in
>>>>
>>>> julia> @sprintf("one line\n
>>>>        another line")
>>>> "one line\n \nanother line"
>>>>
>>>>
>>>>
>>>> quinta-feira, 27 de Agosto de 2015 às 13:08:50 UTC+1, [email protected] 
>>>> escreveu:
>>>>>
>>>>> Literal strings consist of all the characters between the opening and 
>>>>> ending quotes. That includes the end of line characters if they occur 
>>>>> between the quotes.  The \n is the way Julia prints embedded newline 
>>>>> characters in strings to make the character visible similar to the way an 
>>>>> embedded " character is printed as \". 
>>>>>
>>>>> julia> a = "abcdef
>>>>>        ghij"
>>>>> "abcdef\nghij"
>>>>>
>>>>> julia> show(a)
>>>>> "abcdef\nghij"
>>>>> julia> print(a)
>>>>> abcdef
>>>>> ghij
>>>>>
>>>>> To split a string literal over more than one line without including 
>>>>> the end of line in the string you catenate two separate strings:
>>>>>
>>>>> julia> "abcdef" *
>>>>>        "ghij"
>>>>> "abcdefghij"
>>>>>
>>>>> Cheers
>>>>> Lex
>>>>>
>>>>> On Thursday, August 27, 2015 at 9:29:37 PM UTC+10, J Luis wrote:
>>>>>>
>>>>>> Yes, and we can also do
>>>>>>
>>>>>> julia> replace(@sprintf("one line
>>>>>>         another line"), '\n', "")
>>>>>> "one line another line"
>>>>>>
>>>>>> but this is ugly and should not be necessary.
>>>>>> The more I think on this more it looks like a bug to me. 
>>>>>>
>>>>>> quinta-feira, 27 de Agosto de 2015 às 05:39:59 UTC+1, Tero Frondelius 
>>>>>> escreveu:
>>>>>>>
>>>>>>> Maybe the trivial solution is the best solution here:
>>>>>>>
>>>>>>> julia> string = "some text here"
>>>>>>> "some text here"
>>>>>>>
>>>>>>> julia> string = string * " some more text here"
>>>>>>> "some text here some more text here"
>>>>>>>
>>>>>>> julia> 
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thursday, August 27, 2015 at 2:36:17 AM UTC+3, J Luis wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> "\e" is the shorthand for typing the escape character, you will 
>>>>>>>>> probably want to escape the backslash like so: `\\`.
>>>>>>>>>
>>>>>>>>
>>>>>>>> Yes, it was a wrong copy past. Other option is to declare the 
>>>>>>>> variable as
>>>>>>>>  
>>>>>>>>  
>>>>>>>>
>>>>>>>>> It looks like you may be trying to create a command string, but 
>>>>>>>>> you've used string delimiters (") instead of cmd delimiters (`).
>>>>>>>>>
>>>>>>>>
>>>>>>>> Right, its a command string but it needs to be a string that is 
>>>>>>>> later passed to the external program who will parse it. For example, 
>>>>>>>> this 
>>>>>>>> does a DouglasPeucker line simplification of a ... random line
>>>>>>>>
>>>>>>>> julia> t = gmt("simplify -T0.2", rand(50,2))
>>>>>>>> 40x2 Array{Float64,2}:
>>>>>>>>  3.05622e-5  0.225977
>>>>>>>>  0.43428     0.902914
>>>>>>>>  0.290981    0.230531
>>>>>>>>  0.757591    0.71268
>>>>>>>> ...
>>>>>>>>  
>>>>>>>>
>>>>>>>>> Julia always uses the entire literal string (include embedded 
>>>>>>>>> newlines) until the closing " character). Because some characters 
>>>>>>>>> (like a 
>>>>>>>>> newline) cannot be directly printed, Julia shows it as \n when 
>>>>>>>>> representing 
>>>>>>>>> it in "" quotes to display the variable. Similarly, it prints a 
>>>>>>>>> literal " 
>>>>>>>>> as \" so that you can tell that the " is part of the string and not 
>>>>>>>>> indicating the termination of the string.
>>>>>>>>>
>>>>>>>>
>>>>>>>> So, one can't create  strings without that '\n' whose construct 
>>>>>>>> spans over more than one line?
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Aug 26, 2015 at 7:00 PM J Luis <[email protected]> wrote:
>>>>>>>>>
>>>>>>>>>> I need to build a command as a string to pass to an external 
>>>>>>>>>> program (GMT), so I started to build it this way
>>>>>>>>>>
>>>>>>>>>>     julia> ps   = "V:\example_23.ps";
>>>>>>>>>>
>>>>>>>>>>     julia> name="Rome";
>>>>>>>>>>
>>>>>>>>>>     julia> "pscoast -Rg -JH90/9i -Glightgreen -Sblue -A1000 -Dc 
>>>>>>>>>> -Bg30
>>>>>>>>>>             -B+t\"Distances from " * name * " to the World\" -K 
>>>>>>>>>> -Wthinnest > " * ps
>>>>>>>>>>
>>>>>>>>>>     "pscoast -Rg -JH90/9i -Glightgreen -Sblue -A1000 -Dc -Bg30\n 
>>>>>>>>>> -B+t\"Distances from Rome to the World\" -K -Wthinnest > V:\
>>>>>>>>>> example_23.ps"
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Two things here. Shouldn't the \" show up as quote char in the 
>>>>>>>>>> string (that is , without the '\')?
>>>>>>>>>>
>>>>>>>>>> But the second is worst. Why is it adding that '\n' (note it 
>>>>>>>>>> after the '-Bg30')?
>>>>>>>>>> Because of this spurious '\n' the call to the GMT program fails. 
>>>>>>>>>> It does work if I create the cmd string in a single line but I 
>>>>>>>>>> should not 
>>>>>>>>>> be forced to do so
>>>>>>>>>>
>>>>>>>>>> Thanks
>>>>>>>>>>
>>>>>>>>>> Joaquim 
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>
>

Reply via email to