November 23, 2006
Wolven wrote:
>    I, for one, support your idea.  Years ago, I wondered why they didn't pick some
> better character than a single and\or double quotes to bracket literals with.
> Personally, I like the minature << and >> characters (ASCII decimal 171 and 187).


I'm sorry to nitpick, but that's not ASCII. "ALT-171", "-187" depend on the PC's code page.. I would definitely not be smart to pick characters outside the ASCII range (0-127)

L.
November 23, 2006
Hasan Aljudy skrev:
> 
> 
> John S. Skogtvedt wrote:
>> Lionello Lunesu skrev:
>>> Oh, by the way:
>>>
>>> "
>>>     if (k & e.Shift) { ret ~= ""Shift""; }
>>>     if (k & e.Ctrl)  { if (ret) ret~=""|""; ret ~= ""Ctrl""; }
>>>     if (k & e.Alt)   { if (ret) ret~=""|""; ret ~= ""Alt""; }
>>>     if (!ret) ret = ""None"";
>>> "
>>>
>>> ;)
>> In python one can use:
>>
>> r'''if (k & e.Shift) { ret ~= "Shift"; }
>> if (k & e.Ctrl)  { if (ret) ret~="|"; ret ~= "Ctrl"; }
>> if (k & e.Alt)   { if (ret) ret~="|"; ret ~= "Alt"; }
>> if (!ret) ret = "None"'''
>>
>> or:
>>
>> r"""if (k & e.Shift) { ret ~= "Shift"; }
>> if (k & e.Ctrl)  { if (ret) ret~="|"; ret ~= "Ctrl"; }
>> if (k & e.Alt)   { if (ret) ret~="|"; ret ~= "Alt"; }
>> if (!ret) ret = "None\""""
> 
> but if D has ''' or """ the problem will still manifest in the same way!!
> 
> counter example code:
> auto x = """hey!''""";
> auto y = '''yo!''';
> //did you think you can use ` to do this?
> auto z = """ oi ` oi """;
> 
Why? The following works in D:
auto z = " oi ` oi ";

November 23, 2006
renox wrote:
> Bah, I feel that putting any fixed delimitor for string is bond to create a
> problem for some user whether it is simple, double quotes..
> 
> Why not reuse a good idea from the shell: <<FOO .... FOO
> putting a customisable end-of-text word can avoid many problem.
> 
> Sure this makes the parser a bit more complex, but not that much..
> So for D it would be something like:
> r <word>" ... "<word> where word is some text without space
> or r(<word>)" .... "<word>  or the same thing but with a keyword "raw" instead of r.
> 
> Comments?

I wouldn't mind that, having gotten used to such "here-is documents" in languages like Perl and PHP.

--bb
November 23, 2006
Bill Baxter wrote:
>  From the spec:  'There are no escape sequences inside r" ":'
> 
> Shouldn't there be an exception for the " character itself?

That would defeat the whole point.

> Right now the only way to put the quote into a wysiwyg string like
>     foo"bar
> is something like:
>     r"foo" ~'"'~ r"bar";
> or
>     r"foo" "\"" r"bar";
> or
>     r"foo" `"` r"bar";

You missed off

    r"foo" \" r"bar";

> It would be a lot nicer if one could just do:
> 
>     r"foo\"bar";

Then how would one put a backslash at the end of a wysiwyg string?

<snip>
> The goal is that the output string should look as much like the original text as possible.  One main use will be for embedding short script programs (like lua or minid) inside a D executable.
> 
> This:
>     if (k & e.Shift) { ret ~= " `"` r"Shift" `"` r"; }
>     if (k & e.Ctrl)  { if (ret) ret~=" `"` r"|" `"` r"; ret ~= " `"` r"Ctrl" `"` r"; }
>     if (k & e.Alt)   { if (ret) ret~=" `"` r"|" `"` r"; ret ~= " `"` r"Alt" `"`
> r"; }
>     if (!ret) ret = " `"` r"None" `"` r";
> 
> definitely does not look very much like the original code.  :-(
<snip>

I see now.  Do you read the input line by line?  If so, you could detect whether each line contains '"' or '`', and switch between r"..." and `...` at the beginning of the line if necessary.  You'll only need such messy code as the above for lines that contain both characters.

BTW I've used the search and replace technique before.  See

http://smjg.port5.com/wwwep/quines/d.html

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.
November 23, 2006
== Quote from Hasan Aljudy (hasan.aljudy@gmail.com)'s article
> renox wrote:
> > Bah, I feel that putting any fixed delimitor for string is bond to create a problem for some user whether it is simple, double quotes..
> >
> > Why not reuse a good idea from the shell: <<FOO .... FOO putting a customisable end-of-text word can avoid many problem.
> >
> > Sure this makes the parser a bit more complex, but not that much..
> > So for D it would be something like:
> > r <word>" ... "<word> where word is some text without space
> > or r(<word>)" .... "<word>  or the same thing but with a keyword "raw" instead
of r.
> >
> > Comments?

> Walter likes to keep the lexer independent of the parser.
> I don't understand your suggestion very well, but it seems to me that it
> will make the lexer dependent on the parser, and maybe even on the
> semantic analyzer. Well, depending on how do you define these "words".

Do you know 'here strings' in shell/Perl?

My suggestion is that D could provide the same thing (with a syntax more D-like of course) instead of trying to find the "mythical delimiter" for wysiwyg strings which would please everyone as it doesn't exist..

I'm not sure if 'here strings' makes the lexer dependant on the parser or not, I must admit that I'm not very good at grokking compilers.

renoX


November 23, 2006
Stewart Gordon wrote:
> Bill Baxter wrote:
> 
> You missed off
> 
>     r"foo" \" r"bar";

Thanks.  Didn't know that would work.

>> It would be a lot nicer if one could just do:
>>
>>     r"foo\"bar";
> 
> 
> Then how would one put a backslash at the end of a wysiwyg string?

Yeh, using "" for " would be better, as Lionello pointed out.  The only problem is that it changes the meaning of r"""" from an empty string (currently) to a string

Python has r-strings too, and their rules are really wacky.  \" escapes the quote charater, *but* the backslash still appears in the output. And r"\" is not possible.

At least D's rule is easy to remember!

> I see now.  Do you read the input line by line?  If so, you could detect whether each line contains '"' or '`', and switch between r"..." and `...` at the beginning of the line if necessary.  You'll only need such messy code as the above for lines that contain both characters.

I think I should just accept that raw strings are not the right tool for this job.  I'll just stick with regular strings as the default and hope for Perl-ish "here documents" someday.

--bb
1 2
Next ›   Last »