Erlang predefined macros in LFE

49 views
Skip to first unread message

Unix One

unread,
Mar 24, 2017, 11:26:16 AM3/24/17
to Lisp Flavoured Erlang
Hello,

Erlang has some predefined macros [1] like ?FILE, ?MODULE, etc.. Are
they or their equivalents accessible from LFE? I looked at both the
tutorial [2] and the reference guide [3] but couldn't find a reference
to predefined macros.

Thank you!

[1] http://erlang.org/doc/reference_manual/macros.html#id85705
[2] https://lfe.gitbooks.io/tutorial/content/macros/macros.html
[3] https://lfe.gitbooks.io/reference-guide/13.html

Duncan McGreggor

unread,
Mar 24, 2017, 5:31:55 PM3/24/17
to Lisp Flavoured Erlang
You can use (MODULE) -- which I use all the time. I believe that (FILE) as also been added. Note that LFE doesn't track line numbers in functions -- only the line at which the function starts.

d


--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-erlang+unsub...@googlegroups.com.
To post to this group, send email to lisp-flavoured-erlang@googlegroups.com.
Visit this group at https://groups.google.com/group/lisp-flavoured-erlang.
For more options, visit https://groups.google.com/d/optout.

Unix One

unread,
Mar 24, 2017, 6:05:24 PM3/24/17
to lisp-flavo...@googlegroups.com
On 03/24/2017 02:31 PM, Duncan McGreggor wrote:
> You can use (MODULE) -- which I use all the time. I believe that (FILE)
> as also been added. Note that LFE doesn't track line numbers in
> functions -- only the line at which the function starts.

Got it - (MODULE) works, (FILE) does not. Apparently, I was trying
different syntaxes around ?FILE and didn't think to do the same for
MODULE - my bad.

Here's what I have (latest pull from LFE develop branch):
Erlang/OTP 19 [erts-8.3] [source-d5c06c6] [64-bit] [smp:4:4]
[async-threads:10] [hipe] [kernel-poll:false]
LFE v1.3-dev

And yep, I completely understand about line numbers - they don't make
any sense in the machine world anyway. It would be nice to have (FILE)
though.

Thank you!

Duncan McGreggor

unread,
Mar 24, 2017, 7:36:17 PM3/24/17
to Lisp Flavoured Erlang
Sure enough -- there is no (FILE) in the LFE codebase -- just grep'ed the source. I had thought I'd seen an email to the list announcing that, a few years back. Maybe I was confusing that with (LINE) ... dunno.

The good news is, this should be fairly easy for you to create an alias for, depending upon your needs. For example, you could do something like the following (untested):

(filename:basename (clj:get-in (call (MODULE) 'module_info) '(compile source)))


That won't get you the path, since basename just returns the file itself (with the extension, in this case .erl).

Happy LFEing!

d

P.S. I'm using clj:get-in as a convenience -- you can do the same using the proplists module, though in a more verbose way.

P.P.S. If we're going to use the clj module, might as well go full gonzo:

(clj:-> 'code
        (call 'module_info)
        (clj:get-in '(compile source))
        (filename:basename))




Unix One

unread,
Mar 25, 2017, 5:21:06 PM3/25/17
to lisp-flavo...@googlegroups.com
On 03/24/2017 04:36 PM, Duncan McGreggor wrote:
> Sure enough -- there is no (FILE) in the LFE codebase -- just grep'ed
> the source. I had thought I'd seen an email to the list announcing that,
> a few years back. Maybe I was confusing that with (LINE) ... dunno.
>
> The good news is, this should be fairly easy for you to create an alias
> for, depending upon your needs. For example, you could do something like
> the following (untested):
> *
> (filename:basename (clj:get-in (call (MODULE) 'module_info) '(compile
> source)))*
>
> That won't get you the path, since basename just returns the file itself
> (with the extension, in this case .erl).

Thanks, this works well for now (went with the proplists route).

Robert Virding

unread,
Mar 26, 2017, 3:36:22 AM3/26/17
to Lisp Flavoured Erlang
I will add the FILE macro to the next commit of LFE in the develop branch. This is the first time someone has asked for it.

Robert
Reply all
Reply to author
Forward
0 new messages