[erlang-questions] Strings as Lists

Joe Armstrong erlang@REDACTED
Mon Feb 18 15:49:37 CET 2008

One problem with strings unicode, regexps etc. is how you input the string.

To me, embedding regexps, LaTeX etc. in strings is painful and I make
loads of mistakes
forgetting to quote things. Would it be a good idea to have something
like python string literals,
changing the details of course, just to confuse python programmers :-)

To turn off quoting write ~n"abc\n", being short for [97,98,99,92,110],
as opposed to "abc\n" which is short for [97,98,99,10]

This would be especially useful for regexps  ~r" ..." and allow things like
regexp:match(~r".......", ...) to be compiled far better than is possible today.

We could use

~n"...."   turn off quoting
~r"...."    string is a regexp
~x"..."    string is xml
~x/FlunkyStuff ... FunkyStuff  (string is xml terminated by FunkyStuff)
~myExpander/FunkyStuff .... FunckyStuff

(expand ... -- ie the stuff between FunckyStuff literals, with the
function myExpander  (must be defined in a parse
transform) - this mechanism would generalise the ideas of "..." being
syntactic sugar for a list.

So ~Op"......" would mean that "...." was syntactic sugar for *anything*

Is this a good idea or an invitation to write totally unreadable code?

This would make Erlang more powerful (and is backwards compatible) but
less readable - is the extra power
worth the readability?

/Joe Armstrong

2008/2/12 tsuraan <tsuraan@REDACTED>:
> Why does erlang internally represent strings as lists?  In every language
> I've used other than Java, a string is a sequence of octets, just like
> Erlang's binary type.  I know that you can represent a string efficiently by
> using <<"string">> rather than just "string", but why doesn't erlang do this
> by default?  Is it just because pre-12B binary handling wasn't as efficient
> as list handling, or is Erlang intended to support UTF-32?
> Thanks for any input!
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list