[erlang-questions] extend parser to allow single quotes in variable names (or: "let's confuse the text editors!")

25 views
Skip to first unread message

Motiejus Jakštys

unread,
Oct 7, 2012, 12:35:44 PM10/7/12
to erlang-q...@erlang.org
Hi,

In Haskell you can have variable names with single quotes. Imagine for a
moment you are in a perfect world:

oops() ->
A = 1024,
A' = math:log(A) / math:log(2),
io:format("Wow! ~p~n", [A']).

What would you think about this extension?

Regards,
Motiejus
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Richard O'Keefe

unread,
Oct 7, 2012, 5:44:45 PM10/7/12
to Motiejus Jakštys, erlang-q...@erlang.org

On 8/10/2012, at 5:35 AM, Motiejus Jakštys wrote:

> Hi,
>
> In Haskell you can have variable names with single quotes. Imagine for a
> moment you are in a perfect world:
>
> oops() ->
> A = 1024,
> A' = math:log(A) / math:log(2),
> io:format("Wow! ~p~n", [A']).
>
> What would you think about this extension?

I would think it was pointless.

Haskell Erlang
x X
x' X1
x'' X2
x''' X3
x'''' X4
x''''' X5

Spot the pattern?

Haskell (or at least GHC) allows primes inside identifiers too,
but nobody seems to take advantage of that.

Consider f'x 'y'. Want to read _that_ fast?
Consider f'x' y'. Want to tell them apart fast?

SML also allows primes inside and at the end of identifiers.
This is much less of a pain in SML because SML writes
character literals as #"x" rather than 'x'.

There is historically and in good typography a clearly visible
distinction between the apostrophe and the superscript I II III
IV V: (x' is x prime; x'' is x second; x''' is x third, and
the next one is x<sup><small>IV</small></sup>, x fourth, not
x''''). It's only the limitations of old typewriters and ASCII
that lead us to confuse them. Superscript Roman numerals in
Unicode identifiers, fine; using the apostrophe as the quote
character for atoms and also in identifiers, not fine.

Motiejus Jakštys

unread,
Oct 7, 2012, 5:50:02 PM10/7/12
to Richard O'Keefe, erlang-q...@erlang.org
On Mon, Oct 08, 2012 at 10:44:45AM +1300, Richard O'Keefe wrote:
>
> On 8/10/2012, at 5:35 AM, Motiejus Jakštys wrote:
>
> > Hi,
> >
> > In Haskell you can have variable names with single quotes. Imagine for a
> > moment you are in a perfect world:
> >
> > oops() ->
> > A = 1024,
> > A' = math:log(A) / math:log(2),
> > io:format("Wow! ~p~n", [A']).
> >
> > What would you think about this extension?
>
> I would think it was pointless.
>
> Haskell Erlang
> x X
> x' X1
> x'' X2
> x''' X3
> x'''' X4
> x''''' X5
>
> Spot the pattern?
>
> Haskell (or at least GHC) allows primes inside identifiers too,
> but nobody seems to take advantage of that.
>
> Consider f'x 'y'. Want to read _that_ fast?
> Consider f'x' y'. Want to tell them apart fast?

Whoosh! This reasoning is just perfect. I never want to see code like
this. Thanks.

Motiejus

Reply all
Reply to author
Forward
0 new messages