Prev: Can anyone recommend a JavaScript Tree with drag and drop functionality?
Next: capture external js filename
From: nick on 4 Feb 2010 01:46 On Feb 3, 8:20 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > John G Harris wrote: <snip> > >>> In C++ you would write > > >>> var heredoc = "I am a multi-line " > >>> "string; I end when the tokenizer " > >>> "sees a double quote"; <snip> > > var is obviously a type-name, for a type having a constructor with the > > signature > > var(const char * ) > > You really are pitiable. > > Given the existence of preprocessor macros, almost any piece of junk can be > made to compile by a C++ compiler provided there are further definitions > and declarations. Your code *as it is*, however, is clearly not C++ code; > that is, code that compiles *as it is* (in a main() function) without > syntax error messages. What does this have to do with preprocessor macros? "typedef const char * var;" is not a preprocessor macro. Something like "#include <string>" is a preprocessor macro. > > >> Perhaps you meant > > >> std::string heredoc = "I am a multi-line" > >> " string; I end when the tokenizer" > >> " sees a double quote"; > > > That's another example, but not the one I was using. > > Yes, and by contrast this example compiles as it is (in a main() function). > ....but only if you remember to #include <string>. ....and it will only compile to an executable program if you remember to link the C++ standard library, which John's example would not require "as it is". I don't think your definition of "valid C++ code" being equal to "code that will compile inside of main() 'as it is' (with no other code inside main? main has to at least return an int!) really holds much water... Here is a full example of John's (implied) code, this will compile into an executable program (which does nothing) without errors. No libraries need to be linked, and no preprocessor instructions are used. int main() { typedef const char * var; var heredoc = "I am a multi-line " "string; I end when the tokenizer " "sees a double quote"; return 0; } Here is an example of your (implied) code. #include <string> int main() { std::string heredoc = "I am a multi-line" " string; I end when the tokenizer" " sees a double quote"; return 0; } // make sure you link the standard C++ library! // gcc -lstdc++ foo.cpp In other words, both examples would really need more stuff in addition to main() to compile, but since this isn't really a C++ audience it doesn't matter. The point was the way the quoted text is written: (doesn't matter) = "text, text " "and other text"; ....but you seem to have missed it. -- Nick
From: John G Harris on 4 Feb 2010 11:32 On Thu, 4 Feb 2010 at 02:20:11, in comp.lang.javascript, Thomas 'PointedEars' Lahn wrote: >John G Harris wrote: > >> Thomas 'PointedEars' Lahn wrote: >>> John G Harris wrote: >>>> Stefan Weiss wrote: >>>>> I've always wondered why multi-line string literals >>>>> aren't possible in JavaScript. AFAICS, there's nothing ambiguous about >>>>> this syntax: >>>>> >>>>> var heredoc = "I am a multi-line >>>>> string; I end when the tokenizer >>>>> sees a double quote"; >>>>> >>>>> This is standard practice in many other programming languages. >>>> <snip> >>>> >>>> In C++ you would write >>>> >>>> var heredoc = "I am a multi-line " >>>> "string; I end when the tokenizer " >>>> "sees a double quote"; >>> No, that is not C++ code. >> >> You time-waster. > >Pot, kettle, black. > >> It's perfectly valid C++ code. > >No, it is not. > >> var is obviously a type-name, for a type having a constructor with the >> signature >> var(const char * ) > >You really are pitiable. > >Given the existence of preprocessor macros, almost any piece of junk can be >made to compile by a C++ compiler provided there are further definitions >and declarations. Your code *as it is*, however, is clearly not C++ code; >that is, code that compiles *as it is* (in a main() function) without >syntax error messages. > >Get a life. <snip> Here's a little program that compiles, links, and runs using Borland (as was) C++ Builder 6 Pro : //-- 'var' demo 2010-2-4 #pragma hdrstop #include <iostream> class var { private: const char * str; public: var(const char * s) { str = s; } const char * value() { return str; } }; // class var #pragma argsused int main(int argc, char* argv[]) { var heredoc = "I am a multi-line " "string; I end when the tokenizer " "sees a double quote"; std::cout << heredoc.value() << std::endl; return 0; } // main When run from a Win Console and redirected to a file it outputs : I am a multi-line string; I end when the tokenizer sees a double quote Prove me wrong if you can. John -- John Harris
From: Thomas 'PointedEars' Lahn on 4 Feb 2010 12:00 John G Harris wrote: > Thomas 'PointedEars' Lahn wrote: >> John G Harris wrote: >>> Thomas 'PointedEars' Lahn wrote: >>>> John G Harris wrote: >>>>> Stefan Weiss wrote: >>>>>> I've always wondered why multi-line string literals >>>>>> aren't possible in JavaScript. AFAICS, there's nothing ambiguous >>>>>> about this syntax: >>>>>> >>>>>> var heredoc = "I am a multi-line >>>>>> string; I end when the tokenizer >>>>>> sees a double quote"; >>>>>> >>>>>> This is standard practice in many other programming languages. >>>>> <snip> >>>>> >>>>> In C++ you would write >>>>> >>>>> var heredoc = "I am a multi-line " >>>>> "string; I end when the tokenizer " >>>>> "sees a double quote"; >>>> No, that is not C++ code. >> [...] >>> It's perfectly valid C++ code. >> [...] >>> var is obviously a type-name, for a type having a constructor with the >>> signature >>> var(const char * ) >> >> [...] >> Given the existence of preprocessor macros, almost any piece of junk can ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> be made to compile by a C++ compiler provided there are further ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^ >> definitions and declarations. Your code *as it is*, however, is clearly ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> not C++ code; that is, code that compiles *as it is* (in a main() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> function) without syntax error messages. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> >> [...] > > Here's a little program that compiles, links, and runs using Borland (as > was) C++ Builder 6 Pro : > > [...] > class var ^^^^^^^^^ > [...] > int main(int argc, char* argv[]) > { > var heredoc = "I am a multi-line " > "string; I end when the tokenizer " > "sees a double quote"; > std::cout << heredoc.value() << std::endl; > return 0; > } // main > > > When run from a Win Console and redirected to a file it outputs : > > I am a multi-line string; I end when the tokenizer sees a double quote > > > Prove me wrong if you can. I'll rest my case instead. You still manage to miss the point. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: John G Harris on 4 Feb 2010 16:18 On Thu, 4 Feb 2010 at 18:00:12, in comp.lang.javascript, Thomas 'PointedEars' Lahn wrote: >John G Harris wrote: I wrote an extract from my little program, thus : <snip> >> var heredoc = "I am a multi-line " >> "string; I end when the tokenizer " >> "sees a double quote"; <snip> If I'd included the rest of the program I'm sure that some loud-mouth would have complained about including so much irrelevant text, see RFC ... , and maybe the FAQ. >You still manage to miss the point. The point is that Stefan wrote an example of a multi-line string literal and wished it were legal in ECMAScript. I wrote an example showing how C++ does multi-line string literals, a better way in my opinion. Another thing: you forgot to tell Stefan that his 'program' would be rejected by any good Lint program on the grounds that heredoc is never used. John -- John Harris
From: Michael Wojcik on 4 Feb 2010 15:54
Thomas 'PointedEars' Lahn wrote: > > Still it remains to be seen if there are enough programming languages that > do not require special syntax to justify your "many". For example, it does > not apply to the following languages I know rather well: BASIC (and > variants), Pascal (variants, and derivates), C (variants, and derivates), > Tcl (and derivates), Java, and Python. (And maybe I forgot some.) Add COBOL and FORTRAN, so if the metric were source lines of code, we could say that most existing software is written in a language that does not allow string literals to be split across lines. Personally, I prefer C's compromise: string literals can't contain line terminators, but adjacent string literals are concatenated during translation, so it's still convenient to create long literals. I generally prefer this even to here-doc syntax in Bourne shell and derivatives, as the latter tends to break the source formatting, even with the tab-removal option. -- Michael Wojcik Micro Focus Rhetoric & Writing, Michigan State University |