Wiki Diff forum-msg-id-130502-edit, revision #2 to tip

Original date:2016-10-29 07:26:55
Original date:2016-10-28 22:46:10
Edited by: petelomax
Subject: Re: Rosetta code: help needed

[quote ed_davis]
[quote petelomax]
I also think \n handling in strings is suspect and could do with clarifying/extra tests. \\
C# has code in the lexer, Python and zkl have a few {{{.replace("\\n", "\n")}}} in the vm|interpreter.\\
Other solutions seem to be wholly unaware of their existence.
[/quote]

...
Which is what I expected.
[/quote]
I was fully expecting Python to appear to work, because of the .replace().\\
I completely missed the similar code in vm/C (translate) and AST/C (fetch_string_offset).\\

Let me rephrase:\\
'\n' is lex'd to {{{10}}}\\
Should "\n" be lex'd to {{{{'\\','n'}}}} (as it is now) or {{{{10}}}}?\\
To me it does not feel right to perform such basic string substitutions at run-time, when they could/should be done at compile-time.\\
Granted, the "proper" lex will create string constants that need slightly more effort to dump (and slightly less to execute).\\
[edit: I just checked and the C# Token.ToString does indeed have a {{{Value.Replace("\n", "\\n")}}} which other solutions do not.]\\
[**edit2**: Having said all that, and slept on it, I can now more clearly see that either way **is** perfectly valid - it might help to say that.]
Granted, the "proper" lex will create string constants that need slightly more effort to dump (and slightly less to execute).

I will also say that supporting {{{'\\'}}} but prohibiting {{{"\\"}}} is plain wrong; it should at least be optional, otherwise I cannot factor out common code!

Regards, Pete

Search



Quick Links

User menu

Not signed in.

Misc Menu