[erlang-questions] leading underscores on variables versus _

Tony Rogvall <>
Wed Feb 7 08:38:27 CET 2007


Here is a Swedish example when we enable full language support in  
Erlang. Note that
we must declare the language before the module declaration.


-language(swedish).
-enhet(är_detta_läsbart_för_andra_än_svenkar).

-kompilator(exportera_allt).

varför_kan_vi_inte_även_ta_med_nyckelord(VÄRDET) ->
	om VÄRDET > 10 ->
		fall VÄRDET är
			11 -> okej;
			12 -> {fel, av_mig}
			_Annat_Värde -> {fel,igen}
		slut;
	sant ->
		{fel,en_gång_till}
	slut.

/Tony


On 6 feb 2007, at 23.59, Richard A. O'Keefe wrote:

> Matthias Lang <> wrote:
> 	Changing _x to behave as many (most?) initially expect would break
> 	backwards compatibility, but only for misleading code such as the
> 	above...
> 	
> Wrong.
>
> Cast your mind back to 1986 and consider someone writing
> Quintus Prolog in Japanese.  All Japanese characters were
> taken to be LOWER case, so that they could be used for
> atoms and predicate names.
>
>     Japanese programmers would surely like to write Erlang
>     function names using their own language and script, no?
>
> But that means that a variable name cannot begin with a
> Japanese character.  That's fine, Japanese Prolog programmers
> thought of the convention as "to name a variable, put an
> underscore in front of a word or phrase".
>
>     Japanese programmers would surely like to name Erlang
>     variables using their own language and script, not?
>
> So there HAS to be a way of writing a variable name that does not
> involve starting it with a Latin capital letter, and that way is
> to use an underscore.  It is ESSENTIAL that leading underscores
> NOT cause any special treatment; in particular it is essential that
> they should not cause identifiers to be treated as anonymous
> variables.
>
> I note that Prolog, Mercury, Clean, and Haskell all use "_" for
> anonymous variables, and none of them has rule about other variable
> names starting with "_" being unusual, and now you know one reason
> why they don't.
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list