I have found why most of the macros are missing. I need to fix the handling of the macro argument variables in the macro body. Now I convert the whole macrobody into a backquote form, which is good, but it means that I must unquote the argument variables. The way I have it done it so far does not work when they occur in patterns. I will fix it in some way.
Most, if not all, of what is in eunit.hrl should be macros to get them working in the best way. Especially if they use MODULE, FILE or LINE. If it very difficult to get the auto-converting to work properly then it might be worthwhile doing some important .hrl files by hand and putting them in lfe/include. eunit.hrl is really rather straight-forward.
Doing MODULE, FiLE and LINE is not that hard:
- MODULE is easiest to fix by defining it in defmodule.
- FILE can be initially set by the compiler and modified when doing include-file and include-lib.
- LINE is more difficult as we don't have the same line info as in vanilla erlang where every token has a line field. As macros are done on after parsing when I have studiously removed everything but the data. A solution is to do what the compiler does and use the line number of the start of the function definition.
I will fix MODULE and FILE and think more about LINE.
The file lfe/test/test-server.lfe is an example of rewriting test_server.hrl into LFE and adding some necessary macros for the tests. test_server is used by common test. I took a few of the standard Erlang test cases and translated them to LFE for testing LFE. The macro eif (erlang if) is there because some test cases used a vanilla erlang if. Unfortunately the common test system assumes erlang .erl files. A solution would be to write the test cases in LFE but have .erl file wrappers which compile them. Must think about this.
Most of the eunit macros can also be used in common test. I personally prefer common test because it is based on keeping the test cases in separate test suites separate from the tested code.
Robert
On Wednesday, May 15, 2013 11:41:26 PM UTC+2, dun...@cogitat.io wrote:Robert, while I'm waiting for prognosis on eunit.hrl, I thought I'd try my hand at implementing a simple lfeunit module. Needless to say, ?MODULE, ?FILE, and ?LINE are the first things I ran into ;-)
Is there some code you could point to that would give me some hints on how I might go about implementing these in pure lfe? I couldn't find them defined in any .erl files... have I overlooked something, or are they done in C?
I did run across this, though: http://erlang.2086793.n4.nabble.com/Why-no-FUNCTION-macro-td2099004.html and that has some nice general info (e.g., I didn't know about process info:
(: erlang process_info (self))
Thanks!
d
On Sunday, March 3, 2013 3:42:19 PM UTC-8, rvirding wrote:No, they are not available in LFE today. If they were available they would be standard macros which you would refer to as with other macros, (MODULE) (FILE) (LINE) etc. MODULE and LINE would be easy to add and I will fix it the next time I look at the macro expander. Though LINE is not that useful as the only line numbers which exists are those of the beginning of each form.
Robert
On Sunday, March 3, 2013 11:56:16 PM UTC+1, ds26gte wrote:How does one refer to these vanilla Erlang macros in LFE? Are they even available in LFE?I tried many ways of referring to them, encasing them in parens, changing case, dropping the ?, etc., but no dice.--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-e...@googlegroups.com.
To post to this group, send email to lisp-flavo...@googlegroups.com.
Visit this group at http://groups.google.com/group/lisp-flavoured-erlang?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
First attempt at defining the macro MODULE has now been pushed to develop. The MODULE macro is defined automatically by the defmodule macro expands to the quoted module name.