Syntax is throughing my understanding off.

Eric Newhuis enewhuis@REDACTED
Thu Sep 23 06:33:25 CEST 2004


The previous response still holds.

Erlang needs a hint that the function name is still just an atom like every
other function name.  There is nothing special about the use of an atom in
the function name.

The following are equivalent:

myfun () -> 0.

'myfun' () -> 0.


But because Erlang treats # as a special character you cannot declare an
atom in a function declaration starting with the # sign.  You must
explicitly tell the parser/lexical analyzer that you are feeding it an atom.

<atom> <left-paren> <param-list> <right-paren> <arrow> <function-body> <dot>

Atoms are expressed as words beginning with lower case letters or as
single-quoted character globs.

You'll also see stuff like this from time to time:

'CapitalLetterFunctionName' () -> 0.

'$BettingThatNobodyElseThinksOfUsingDollarSignToAvoidGlobalNameConflict'()
-> 0.

Ciao.  Happy Erlanging.


On 9/22/04 8:51 PM, "Edward Ing" <edward.ing@REDACTED> wrote:

> Okay,
> 
> In most programming languages I work with, the name of a function is a
> 'symbol'.   And characters like " ' " are tokens which demarcate a literal
> in between. Is it the case that erlang evaluating '#text#' to make up the
> function name symbol?
> 
> ----- Original Message -----
> From: "Bengt Kleberg" <bengt.kleberg@REDACTED>
> To: <erlang-questions@REDACTED>
> Sent: Wednesday, September 22, 2004 1:44 AM
> Subject: Re: Syntax is throughing my understanding off.
> 
> 
>> Edward Ing wrote:
>>> Hi,
>>> I am new to Erlang and I am trying to learn to use it to manipulate XML.
>>> I am lookng into the source files and see this definition:
>>> 
>>> '#text#'(Text) ->
>>>     export_text(Text).
>>> 
>>> I cannot find any reference material to explain what this means, the
>>> '#text#'(Text).
>>> 
>>> Obviously it is defining a function, but what is how do you invoke this
>>> function? Is '#text#' some kind of macro substitution?
>> 
>> 1 you call the function like an ordinary function:
>> 
>> '#text#'("a text").
>> 
>> (or F = '#text', F("a text"), etc.)
>> 
>> 
>> 2 it is not a macro. (macros are accessed with '?' ,ie ?A_MACRO). what
>> is happening is the creation of an _atom_ . atoms are usually small
>> letters, numbers and '_', but they can be anything. you just have to
>> single quote (') them. eg 'This is an atom!'
>> 
>> 
>> bengt





More information about the erlang-questions mailing list