1 Introduction

1.6 Loading Files

1.6.1 Loading Files in the REPL

There are several ways in which one may load files in LFE.

1.6.1.1 slurp

As mentioned in the section on LFE's REPL, slurping a file makes all functions and macros defined in the file available in the shell. One does not need to reference the module (and, in fact, attempting to do so will result in an error. Also, note that only one file can be slurped at a time; slurping a new one removes all data about the previous file.

> (slurp "my-module.lfe")
#(ok my-module)
>

1.6.1.2 c

Compiling a module from the REPL is what you need if you wish to work with multiple modules simultaneously:

> (c "my-module")
#(module my-module)
>

1.6.1.3 ec

You can also load Erlang files in LFE:

> (ec "../lfe/src/lfe_macro.erl")
#(ok lfe_macro)
>

1.6.1.4 l

If a module is in your Erlang/LFE path, you can load that too:

> (l 'mochiweb)
(#(module mochiweb))
>

1.6.2 Loading Files in Modules

Code may be included wholesale into LFE modules by either using include-file or include-lib.

1.6.2.1 include-file

If you have records or data that you would like to be available to more than one module, you can put those in a dedicated file and pull them in to your modules. For example, let's say I had defined the following constants in the file include/consts.lfe:

(defmacro *base-cool-factor* _ `0.8)
(defmacro *earth-adjustment* _ `0.3)

Then, in the following two files I could easily use those constants by including them:

(defmodule zaphod
  (export all))

(include-file "include/consts.lfe")

(defun get-coolness ()
  (let ((zaphod-cool-factor 0.9))
    (* (*base-cool-factor*) zaphod-cool-factor)))
(defmodule arthur
  (export all))

(include-file "include/consts.lfe")

(defun get-coolness ()
  (let ((arthur-cool-factor 0.1))
    (* (*base-cool-factor*) (*earth-adjustment*) arthur-cool-factor)))

1.6.2.2 include-lib

TBD