support of multiline string - with and without escaping and interpolation

285 views
Skip to first unread message

Zaxebo Yaxebo

unread,
Aug 25, 2014, 9:18:28 PM8/25/14
to haxe...@googlegroups.com
single " and single '  are very normal to occur in a single large multiline string. 
Even "MINIMALIST" ELEGANT LANGUAGE PYTHON also support triple quotes for multiline string. 

support for "multiline escaped interpolation string" and "unescaped+without interpolation string" and custom interpolators on string - may be built in haxe 

haxe users are asking for this feature in haxe since year 2009. 
I would humbly request to kindly reconsider the decision and implement this. 

If needed I am ready to pay a humble contribution of upto "USD 100 dollars" as development cost of issue #3276 and issue #3277 
==============
right now we have to go for "haxe-m4" to achive this, but that makes it unintelligible for haxe editors for syntax colouring, due to an additional language "m4" sneaking in 



Franco Ponticelli

unread,
Aug 25, 2014, 10:00:33 PM8/25/14
to haxe...@googlegroups.com
Do you need this only to avoid escaping \" ? 
If you have that much text, have you considered to move it outside the haxe code? You can achieve that using "resources" or a simple macro.
I find the single and double quotes very simple and elegant and I never felt the need for triple quotes. Again when I have long strings (like templates) I prefer to keep them separate and let the compiler do its work without impacting on performances.


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Jason O'Neil

unread,
Aug 25, 2014, 10:12:59 PM8/25/14
to haxe...@googlegroups.com
I think Franco's advice is good. I have a very simple macro I have for including long strings from a file at compile time:
var file = CompileTime.readFile("README.md"); // same as double quotes (no interpolation) directly in the source code.
var file = CompileTime.interpolateFile("test.txt"); // same as single quotes (uses interpolation) directly in the source code.
var htmlString = CompileTime.readMarkdownFile("test.md"); // parse text from markdown, insert as HTML string directly in the source code.
It takes care of all the quoting and escaping for you. It also has a few other helpers. Use `haxelib install compiletime` to get the library. Documentation here: https://github.com/jasononeil/compiletime
You could also introduce your own string interpolation using macros.  In Haxe 2.10 there was Std.format(), the same as using single quotation strings now.  The macro is still available in the standard library, and it's very short, it would not be hard to create your own version: https://github.com/HaxeFoundation/haxe/blob/development/std/haxe/macro/Format.hx

You could even use a build macro to make this the default string interpolation on a given class.

Jason

Zaxebo Yaxebo

unread,
Aug 26, 2014, 12:42:44 AM8/26/14
to haxe...@googlegroups.com, he...@jasono.co
Actually i use haxe for my application development, BUT I ALSO USE haxe as my SCRIPTING LANGUAGE due to its fast compiler, which is so fast that it feels almost as interpreter for starting the run of the script.

In case of scripting language it is very essential to have multiline/heredoc. It is no wonder that PHP,Python to C++/C# etc all have this feature. It is a major inconvenience to bundle another "data file"(containing strings) as separate file, when i can just take one single haxe "script" for each major task.

Optional Avoiding of escaping and interpolation, is a super-essential feature needed, which is being constantly under-estimated by haxe core developers probably due to their software development backgrounds. You have to appreciate the concerns of system administrators (Who are already trying to use haxe in their software programs ), now those sysadmins are trying to port their "scripts" too to haxe - to keep a single language for their programs and scripts

It is no wonder all these mainstream languages have this support

scripting languages
    Python
    D language



EVEN MAJOR COMPILED LANGUAGES too have this feature
    "C++ 11" new standard also has introduced raw string literals http://rosettacode.org/wiki/Here_document#C.2B.2B


SUPER-MINIMALISTIC python too has this feature


It is super essential to have this feature for scripting puposes.
Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please  


Zaxebo

Axel Huizinga

unread,
Aug 26, 2014, 1:00:12 AM8/26/14
to haxe...@googlegroups.com
Heredoc syntax would be great indeed - is it so hard to implement it or would it slow down the compiler?

Zaxebo Yaxebo

unread,
Aug 26, 2014, 1:00:34 AM8/26/14
to haxe...@googlegroups.com, he...@jasono.co
In my email above/earlier i mentioned : "In case of scripting language it is very essential to have multiline/heredoc. It is no wonder that PHP,Python to C++/C# etc all have this feature."

the above text should be read as: "In case of scripting language it is very essential to have multiline/heredoc which is neither single quote nor single double quote. It is no wonder that PHP,Python to C++/C#/Scala etc all have this feature."

Zaxebo1

Dan Korostelev

unread,
Aug 26, 2014, 2:02:16 AM8/26/14
to haxe...@googlegroups.com, he...@jasono.co
how come python is minimalistic language? :-)

вторник, 26 августа 2014 г., 8:42:44 UTC+4 пользователь Zaxebo Yaxebo написал:

Zaxebo Yaxebo

unread,
Aug 26, 2014, 10:28:40 AM8/26/14
to haxe...@googlegroups.com, he...@jasono.co
Q) how come python is minimalistic language? :-)

Answer)

"Zen of python" (the python language design guiding principle) - has one following statement :

    ***"There should be one-- and preferably only one --obvious way to do it."****
        
     ==> This shows that being minimalisting language is embedded in core ethos of Python. 
    
    ------------
REFERENCE: 
  Question) How to see "Zen of python" referred above?

  Answer) see Zen of python at http://legacy.python.org/dev/peps/pep-0020/

  OR, on python command prompt type "import this" as the following:
    >>> import this

    The Zen of Python, by Tim Peters

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than *right* now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea -- let's do more of those!


===============
Zaxebo1

Cristian Baluta

unread,
Aug 26, 2014, 11:53:21 AM8/26/14
to haxe...@googlegroups.com
I think is more natural to put long texts into separate files. I don't use soft wrap in code because looks like a mess (not that i have long haxe lines, but maybe i'm looking at html pages with the same editor). If i'd have long texts embedded will be really bad, i'll not be able too read it.
However, i think i'm missing your problem, i have this multiline var which compiles just fine:

var str = "a
b
c";

Juraj Kirchheim

unread,
Aug 26, 2014, 2:17:09 PM8/26/14
to haxe...@googlegroups.com
On Tue, Aug 26, 2014 at 3:18 AM, Zaxebo Yaxebo <zax...@gmail.com> wrote:
> single " and single ' are very normal to occur in a single large multiline
> string.
> Even "MINIMALIST" ELEGANT LANGUAGE PYTHON also support triple quotes for
> multiline string.

Please refrain from statements like this in the future, or someone
(quite possibly me) will take the flame bait.

> support for "multiline escaped interpolation string" and "unescaped+without
> interpolation string" and custom interpolators on string - may be built in
> haxe
> I had requested this as https://github.com/HaxeFoundation/haxe/issues/3276
> and https://github.com/HaxeFoundation/haxe/issues/3276 , but unfortunately
> it was denied.
>
> haxe users are asking for this feature in haxe since year 2009.
> I would humbly request to kindly reconsider the decision and implement this.
>
> If needed I am ready to pay a humble contribution of upto "USD 100 dollars"
> as development cost of issue #3276 and issue #3277
> ==============
> right now we have to go for "haxe-m4" to achive this, but that makes it
> unintelligible for haxe editors for syntax colouring, due to an additional
> language "m4" sneaking in

You can add this through Haxe macros also, in a couple of ways.
However, you have raised the issue of not having editor support. Even
if this were added to the language, it wouldn't give you editor
support. So I am confused about your point here.

You could quite easily implement a macro that would make this fly:

Multiline.string(/*
lots and lots
of text
in here
*/);

But the again, that would make "*/" an unsupported sequence. In triple
quote strings, a triple quote is an unsupported sequence. I don't get
why you can't just use normal strings and escape stuff.

I also really don't get why having another file that contains the
string is so inconvenient. In fact chances are that whatever you've
put in there is another language yet again, so you will probably be
better off having the data in a different file so you get syntax
highlighting.

I think you're being rather obsessed about this. If you could calm
down and explain your use case instead of repeating how Python is so
much better as a language (which really isn't going to win people over
to your cause here ;)) and how desperately you need this. Adding
"Please" a gazillion times won't help either. You're talking to a
bunch of people who survived without this feature for years. Show us
eye opening use cases.

Lastly I would stress what others have pointed out already: use macros
if you need a custom interpolation method.

class Interpolate {
macro static public function f(s:String) { ... }
macro static public function s(s:String) { ... }
}

import Interpolate.*;
import Sys.println;

val height = 1.9;
val name = "James";
println(s("Hello, $name"));
println(f("$name%s is $height%2.2f meters tall"));

You could make `@s"Hello, $name"` work with `@:build` macros, but
really I'm not sure shaving off one more character is worth the effort
here.

Anyway. Try showing concrete problems and concrete examples of how
this would be a real improvement. Chances are *really* slim for any
feature to be added, just because "XYZ has it too". Some languages
garner users with code golfing tricks. Haxe is simply not one of them.
Show us that this is about more ;)

Best,
Juraj

Andy Li

unread,
Aug 26, 2014, 3:33:29 PM8/26/14
to haxe...@googlegroups.com
I enjoy implementing random haxe feature requests with macros as programming exercises. :)
Read the test file for some usage examples. Feel free to challenge my implementation.
Coincidentally I implemented it using comments, just like what Juraj mentioned ;)

Best,
Andy


Simon Krajewski

unread,
Aug 26, 2014, 5:34:27 PM8/26/14
to haxe...@googlegroups.com

Now I wonder if -D doc-gen could be abused in some fun way... ;)

Simon

Nicolas Cannasse

unread,
Aug 26, 2014, 6:32:50 PM8/26/14
to haxe...@googlegroups.com
Le 26/08/2014 21:32, Andy Li a écrit :
> I enjoy implementing random haxe feature requests with macros as
> programming exercises. :)
> Here it is -> https://github.com/andyli/CommentString
> Read the test file for some usage examples. Feel free to challenge my
> implementation.
> Coincidentally I implemented it using comments, just like what Juraj
> mentioned ;)

"There's a macro for that" gets one more victory against "Feature
request". The score is now 154 to 0 :)

Best,
Nicolas

Franco Ponticelli

unread,
Aug 26, 2014, 7:23:12 PM8/26/14
to haxe...@googlegroups.com
No no ... short lambda is definitely not a victory!!! ;)


Zaxebo Yaxebo

unread,
Aug 26, 2014, 9:05:47 PM8/26/14
to haxe...@googlegroups.com

juraj >>>""You could make `@s"Hello, $name"` work with `@:build` macros, but really I'm not sure shaving off one more character is worth the effort here. ""

can you please show me how to do the above with '@:build' macro 

Juraj Kirchheim

unread,
Aug 27, 2014, 2:27:11 AM8/27/14
to haxe...@googlegroups.com
Why don't you start with making `s("....")` and `f("....")` work? Once
you've accomplished that, the rest will be quite trivial ;)
Reply all
Reply to author
Forward
0 new messages