[erlang-questions] Strings as Lists

Matt Kangas kangas@REDACTED
Tue Feb 19 00:03:59 CET 2008

On Feb 18, 2008, at 10:35 AM, Brian Cully wrote:

> On 18-Feb-2008, at 09:49, Joe Armstrong wrote:
>> ~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
> 	perl's qr/w/x operators might be worth looking at. They don't
> completely fix the issue, but they work around it by allowing the
> programmer to specify delimiters.

Interesting ideas! For comparison's sake, and food for thought, here's  
how this issue is handled in several other languages:


Perl: per Brian's comment above, and more (~8 variations)


* single or double-quoted : normal string literals, all escapes  
* Triple-quoted strings ("""example""", '''example''') may contain  
unescaped newlines or quotes
* These may be prefixed by [uU] and/or [rR]
   * u"", U"" = unicode string
   * r"", R"" = raw (regexp) string, not interpreted for escape  


* single-quoted : limited escapes
* double-quoted : all escapes processed, plus variables ($foo) expanded
* "heredoc syntax", ala Perl or Bourne shell


* single-quoted : limited escapes
* double-quoted : all escapes processed
* %q or %Q : user-defined delimiter (ala Perl qr/w/x operators)
* "heredoc syntax"


I like Python's approach, because the elements are "stackable": you  
can combine prefixes to say
which yields three unicode characters ('LATIN SMALL LETTER B',  
'REVERSE SOLIDUS', 'LATIN SMALL LETTER N'). I also find Python triple- 
quotes to be as useful as "heredocs" in perl/php/ruby/bash, but the  
syntax is simpler.


Matt Kangas
kangas@REDACTED – www.p16blog.com

More information about the erlang-questions mailing list