Re: Rosetta code: help needed

new topic     » goto parent     » topic index » view thread      » older message » newer message
ed_davis said...
petelomax said...

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.

... Which is what I expected.

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.]

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu