[erlang-questions] Erlang PP Question

Kannan vasdeveloper@REDACTED
Wed May 30 12:36:25 CEST 2012


Thanks Richard for your response. That makes sense.

Actually what I wanted is to get a macro expand into two different
functions in the source file. My intention was not producing a term.  That
is where the '.' came to be a problem.

It seems it not possible. Anyways I will breakdown the macro into two
different ones.

Kind Regards,
Kannan.


On Wed, May 30, 2012 at 3:58 PM, Richard Carlsson <
carlsson.richard@REDACTED> wrote:

> On 05/30/2012 12:17 PM, Kannan wrote:
>
>> Also, is there a way to expand a single macro into multiple macros,
>> before a final replacement?
>>
>
> If you mean into multiple macro definitions, it is not possible - each
> macro definition is a separate form, and you can't expand one form into
> multiple forms. But multiple uses of macros in the body of another macro is
> not a problem, if that's what you mean:
>
> -define(X, {foo, ?Y, ?Z}).
>
>   /Richard
>
>
>  On Wed, May 30, 2012 at 3:42 PM, Kannan <vasdeveloper@REDACTED
>> <mailto:vasdeveloper@REDACTED**>> wrote:
>>
>>    My bad, please read the second PP as -define.
>>
>>
>>    On Wed, May 30, 2012 at 3:41 PM, Kannan <vasdeveloper@REDACTED
>>    <mailto:vasdeveloper@REDACTED**>> wrote:
>>
>>        Isn't PP takes place before parsing? Isn't PP is simply a string
>>        replacement?
>>
>>
>>
>>        On Wed, May 30, 2012 at 3:03 PM, Richard Carlsson
>>        <carlsson.richard@REDACTED <mailto:carlsson.richard@**gmail.com<carlsson.richard@REDACTED>
>> >>
>>
>>        wrote:
>>
>>            On 05/30/2012 11:26 AM, Kannan wrote:
>>
>>                Hi There,
>>
>>                If -define does just string replacement, why it does not
>>                let me do the
>>                following?
>>
>>                -define(Z, z() -> io:fwrite("z")).
>>                -define(Y, y() -> io:fwrite("y")).
>>                -define(X, ?Y. ?Z.).
>>
>>
>>            In the last line, you have ?Y. followed by whitespace. This
>>            ends the define declaration. Erlang source code is divided
>>            into "forms", where each form ends with . followed by
>>            whitespace (usually newline, but any whitespace or even a
>>            comment can be used). So you have two forms at the end:
>>            '-define(X, ?Y.' and '?Z.).' and none of these are
>>            syntactically valid. It is not possible to make a single
>>            macro expand into two forms.
>>
>>               /Richard
>>
>>
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120530/8a6f6ca4/attachment.htm>


More information about the erlang-questions mailing list