Python style multiline strings for JSTalk?

20 views
Skip to first unread message

Gus Mueller

unread,
Aug 4, 2010, 5:10:59 PM8/4/10
to jstal...@googlegroups.com
I just added experimental support (and only in debug builds) to JSTalk for python style multiline strings. It's done in the preprocessor, and it generates code like so:

var filter = [JSTQuickCIFilter quickFilterWithKernel:"""
kernel vec4 ccc(vec4 c){
return c;
}"""];


Would then turn into:

var filter = JSTQuickCIFilter.quickFilterWithKernel_("kernel vec4 ccc(vec4 c){\n return c;\n}");

Good idea? Bad idea? I'm obviously for it, but I'd love to hear other thoughts if you have an opinion on it.

-gus

--

August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/

Patrick Geiller

unread,
Aug 5, 2010, 10:43:04 AM8/5/10
to jstal...@googlegroups.com
> var filter = JSTQuickCIFilter.quickFilterWithKernel_("kernel vec4 ccc(vec4 c){\n return c;\n}");
>
> Good idea? Bad idea? I'm obviously for it, but I'd love to hear other thoughts if you have an opinion on it.

Good idea ! Will the editor show it's a multiline string ? (With a different color, or a carriage return symbol ?)

-Patrick


Gus Mueller

unread,
Aug 5, 2010, 12:57:43 PM8/5/10
to jstal...@googlegroups.com

No CR symbol, but it is grey like in a string:
http://gusmueller.com/trash/ea432be6-1ece-441d-8b0c-0c4058e673e9.png

Patrick Geiller

unread,
Aug 5, 2010, 3:28:32 PM8/5/10
to jstal...@googlegroups.com
> No CR symbol, but it is grey like in a string:
> http://gusmueller.com/trash/ea432be6-1ece-441d-8b0c-0c4058e673e9.png

Ha, nice. Although the three """ look a bit heavy. Since you're already transforming @"...." to ObjC strings, why not factor the multilines in that syntax ? (Or use another character prefix)

-Patrick

Michael McCracken

unread,
Aug 5, 2010, 3:33:32 PM8/5/10
to jstal...@googlegroups.com
Gus, I like the new syntax, but I like python, so keep that in mind.
I guess javascript doesn't really have a true multiline string?

I laughed when I saw this first email because I was thinking of suggesting a multiline string constant when I saw your earlier CI code sample...

Does your new code allow a single quote " inside the multiline like Python does?
If so, that answers Patrick's question.

Cheers,
-mike


--
You received this message because you are subscribed to the Google Groups "JSTalk Dev" group.
To post to this group, send email to jstal...@googlegroups.com.
To unsubscribe from this group, send email to jstalk-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jstalk-dev?hl=en.


Gus Mueller

unread,
Aug 5, 2010, 7:48:05 PM8/5/10
to jstal...@googlegroups.com

Well, I chose it because that's what python does, and it's already a common syntax. I figured inventing my own wouldn't make sense. I also thought about going with Perl's, but since there's fewer and fewer perl hackers these days…

Gus Mueller

unread,
Aug 5, 2010, 7:49:41 PM8/5/10
to jstal...@googlegroups.com
On Aug 5, 2010, at 12:33 PM, Michael McCracken wrote:

> Gus, I like the new syntax, but I like python, so keep that in mind.
> I guess javascript doesn't really have a true multiline string?

Not that I'm aware of, or at least that JavaScriptKit parses.

> Does your new code allow a single quote " inside the multiline like Python
> does?

Currently it doesn't, but that'd be nice to have.

Jonathan 'Wolf' Rentzsch

unread,
Aug 6, 2010, 3:56:02 AM8/6/10
to jstal...@googlegroups.com
On Aug 5, 2010, at 6:48 PM, Gus Mueller wrote:
> On Aug 5, 2010, at 12:28 PM, Patrick Geiller wrote:
>
>>> No CR symbol, but it is grey like in a string:
>>> http://gusmueller.com/trash/ea432be6-1ece-441d-8b0c-0c4058e673e9.png
>>
>> Ha, nice. Although the three """ look a bit heavy. Since you're already transforming @"...." to ObjC strings, why not factor the multilines in that syntax ? (Or use another character prefix)
>
> Well, I chose it because that's what python does, and it's already a common syntax. I figured inventing my own wouldn't make sense. I also thought about going with Perl's, but since there's fewer and fewer perl hackers these days…

FWIW CoffeeScript also uses triple-quotes for Heredocs:

http://jashkenas.github.com/coffee-script/

The example demonstrates triple-single-quotes (which I prefer -- less visual noise) but it also supports triple-double-quotes.

So you can make at least a small claim of software stare decisis here.

Reply all
Reply to author
Forward
0 new messages