[erlang-questions] Binary string literal syntax

Sean Hinde sean.hinde@REDACTED
Tue Jun 5 19:51:32 CEST 2018


I’ve been writing a lot of Elixir over the last few months (plus Swift, Java, C) and just came back to Erlang. There are a few things I’ve come to very much like about Elixir I think might be quite useful to bring to Erlang.

The first, and topic of this email, is arguably trivial, but having to surround <<“modern”>> string literals with <<>> is irritating and not getting any less so.

It occurred to me we might usefully steal the sigil notation from Elixir to solve this and add other string literal related syntactic niceties.

My proposal would be to add an alternative notation for binary string literals in Erlang along the lines of:

~s”Some binary string” mapping to <<"Some binary string”>>

This would open the door to other alternative notations. e.g. Elixir has one for regex friendly strings:

~r/foo|bar/

String literals containing quotes could also benefit from different delimiter characters e.g.

~s'{"Name":"Tom","Age":10}’ mapping to <<"{\"Name\":\"Tom\",\"Age\":10}”>>

The Elixir docs cover more options: https://elixir-lang.org/getting-started/sigils.html. There are 8 alternative delimiters, and even user defined sigils and interpolation with #{}

If we didn’t want to go as far as Elixir style sigils we could just use a single prefix char.

LFE uses:

#”Some binary string”

or maybe

~”Some binary string”

If people here on the list think there is anything useful in this, and we can reach some kind of rough consensus on how far it makes sense to go I will put some effort into an EEP.

Sean

 - first post since July 2008. It’s good to be back


More information about the erlang-questions mailing list