A proposal for handling literal strings in a computer language that doesn't exist, similar to Lisp. We use the special form literal-strings.
(literal-strings foo bar baz) generates the list ["foo","bar","baz"].
(literal-strings \ )
generates the list [" "]
. Backslash is a quote character.
(let space (head (literal-strings \ ))
assigns the string " "
to the identifier space
. One might also do (list (chr 32)). We use the Haskell convention Strings are lists of Chars.
(concat (intersperse space (literal-strings foo bar baz)) generates the string "foo bar baz". One would probably write a convenience function.
(literal-strings foo\ bar\ baz) generates the list ["foo bar baz"].
(literal-strings foo (bar) baz) generates the list ["foo",bar,"baz"], where bar is the type String output of the function bar. Parentheses are a function escape character, allowing string interpolation.
(literal-strings \(foo\)) generates the list ["(foo)"].
(literal-strings \(foo)) makes the parser cry.
(literal-strings (foo\))) calls a very interestingly named function foo)
which should return a value of type String.
One can do String, or some typeclass for String-like literals, to handle various encodings, etc.
I dislike the normal syntax "abc" because the lexer, especially for IDEs, has a hard time figuring out if a given point is inside or outside a string. The quotation mark only toggles, does not signify whether inside or out. In my proposal, everything is uniform with the rest of the parenthesized syntax.
This is a concrete description of this observation, optimizing for the common case for literal strings in code, rarely needing consecutive multiple spaces.
We might also do (compiled-string-from-file foo.txt) which creates a literal string from the contents of the file foo.txt, as an alternative to lots of quoting. Must be able to determine the file name at compile time. Creates a compile time dependency.
No comments :
Post a Comment