Macro.to_string
, it returns the actual code in a string format and we all knew this.Macro.to_string
to IO.puts
like in the following code snippet. It gives the clean output by printing in new line.loaded_files
in the module Code
used to find the loaded files.iex
inside your terminal and call the function Code.loaded_files
.[]
as output because we haven’t loaded any files so far.hello.ex
with a single function definition hello
which just prints a string “Welcome to the world” for the demo purpose.hello.ex
file as well.Code.loaded_files
. It outputs the path to the file.iex session
iex hello.ex
, you can load them on-fly in iex
session with the help of Code.load_file "path/to/file"
.hello.ex
in our current directory and open iex
session from the same directory.lib/hello.ex
in the project with the following codeHello
and Printee
. The Printee
module comprises of two functions print/0
and show/0
. Here purposely, print/0
is considered as a deprecated function used inside the Hello
module.mix compile
, it gives a warning saying“print/0 is deprecated use show/0”
defmodule
is used to create a module. In similar, Module.create/3
is also used to create a module.Module.create/3
is the definition inside the module is quoted expression.quote
to create a quoted expression.Moduel.create
.keyword list
like [file: String.t, line: Integer ]
or else you can just take the help of Macro.Env.location(__ENV__)
which returns the same.module_definition
. We can use this module_defintion
to pass as second parameter to Module.create/3
function.Foo
with same module functionIO.inspect/2
with binding()
, which returns all variable names and their values:fun/3
is invoked with :laughing
, "time"
it prints:binding
Integer.char_list
. It can be used in two ways either passing the base the base value or not passing.Process.info
, we can extract the process information like linked processes etc…spawn_link
and will try to extract only linked processes. With no surprise, it should give the self
output pid which is the current process in our case.@enforce_keys
attribute. But, you can still use the pattern matching to the keys of a map.name
, blog
to be present inside the map with any values.Thanks to pattern matching.
mix format
. It will take care of all you care about cleaning and refactoring as well. It can assure a clean code base or simply universal code base which maintains some useful standards. This really saves a lot of time.mix format
task and its configuration in detail with screen shots of vivid examples.alias __MODULE__
, we have to type full module name like %User.Authentication{key: "key", token: ".."}
to define the struct but now simply %Auth{key: "key", token: ".."}
will be the better approach.