[erlang-questions] reserved word guaranteed to be atom if single-quoted?

Tony Arcieri tony@REDACTED
Tue Feb 23 01:41:29 CET 2010


I've been surprised what strange places single quoted atoms work.  Things
like module names and record names.  It's pretty spiffy.

On Sat, Feb 20, 2010 at 1:50 AM, Michael Turner <leap@REDACTED> wrote:

> Recently somebody tripped over "query" as a reserved word in Erlang,
> and wondered what it was, and whether there were other reserved words
> that were similarly obscure.
>
> And I've been tinkering with a style of argument passing where one might
> write
>
>  the_frob ({of, This_thing}, {within, That_other_thing}, ....)
>
> as a kind of poor man's syntactic sugar for the folks I'm writing my
> code for (who aren't programmers, much less Erlang programmers, just
> algorithm-specifiers).  Of course, the Erlang parser complains about my
> "of".
>
> Experiment shows that single-quoting seems to work, e.g., Erlang accepts
>
>   {'of', 'query'}.
>
> But it doesn't return quite what I'd expect from the shell.  I get back
>
>   {'of', 'query'}
>
> where I expected
>
>   {of, query}
>
> although I think this because some output pretty-printing metarule is
> being applied here, like "output stuff in a way that's also acceptable
> for input, to the extent reasonable."  Certainly
>
>  atom_to_list('of')
>
> reports what I *did* expect from the Erlang shell: "of", i.e., without
> the single quotes.
>
> I'd like to submit a patch to the relevant part of the Data Types
> section of the User's Manual, which currently reads as follows:
>
> ----
> An atom is a literal, a constant with name. An atom should be enclosed in
> single quotes (') if it does not begin with a lower-case letter or if
> it contains other characters than alphanumeric characters, underscore
> (_), or @.
> ----
>
> That seems incomplete to me.  I'd like to add, "or if it's an Erlang
> reserved word", with a link to the list of reserved words.  It doesn't
> make sense to me that this single-quoting of reserved words would ever
> fail in some future version, but I thought I'd ask, just to be sure.
>
> -michael turner
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


-- 
Tony Arcieri
Medioh! A Kudelski Brand


More information about the erlang-questions mailing list