Erlang: use enable from console?

Inclusion is usually used for the .hrl file at the top of the .erl file.

But I would like to use include from the Erlang console directly.

I am trying to use some functions in a module. I compiled the erl file from the console. But the functions that I want to use do not work without access to the hrl file.

Any suggestions?

+7
include module erlang
source share
3 answers

"But the functions I want to use do not work without access to the hrl file."

This may not be true, but from this I will try to guess that you want to access the entries in the hrl file, which you do not have (usually) in the shell.

If you execute rr(MODULE) , you will load all the entries defined in MODULE (including those defined in the include file included by MODULE ).

Then you can do everything you need from the shell.

(Another thing you might want for testing is adding the -compile(export_all) to your erl file. Awful, but sometimes useful for testing.)

+8
source share

Have you tried the compile:file option? You can pass a list of modules to be included in this way:

 compile:file("myfile.erl", [{i, "/path/1/"}, {i, "/path/2/"}]) 
+2
source share

It costs nothing that jsonerl.hrl does not contain any functions. It contains macros. As far as I know, macros are only time compilation in Erlang.

The easiest way to make them available is to create an .erl file that will actually declare functions implemented in macro terms. Maybe something like this:

 -module(jsonerl_helpers). -include("jsonerl.hrl"). record_to_struct_f(RecordName, Record) -> ?record_to_struct(RecordName, Record). 

... which, after compilation, you can call as:

 jsonerl_helpers:record_to_struct_f(RecordName, Record) 

I do not know why the author decided to implement them as macros; it seems strange, but I'm sure he had reasons.

+2
source share

All Articles