lfescript(1)

πŸ“¦ version 2.2.0, in alpine 3.24, nixos 26.05, nixpkgs unstable

🌸 lfescript(1) β€” LFE scripting, but make it cute 🌸

Hii bestie πŸ’– welcome to the lfescript(1) manual page. This is the LFE scripting support page, and it's literally here to help you run short LFE programs without compiling them first, plus grab the command line arguments in the easiest way. It's giving main character energy, fr fr. ✨

✨ NAME ✨

lfescript β€” Lisp Flavoured Erlang (LFE) scripting support. That's the whole name, no cap. πŸŽ€

πŸ¦‹ SYNOPSIS πŸ¦‹

lfescript provides support for running short LFE programs without having to compile them first and an easy way to retrieve the command line arguments. The way that it skips the compile-first step is iconic. πŸ’…

πŸŽ€ EXPORTS πŸŽ€

Okay so the launch lines are exactly this:

script-name script-arg1 script-arg2 ...

lfescript lfescript-flags script-name script-arg1 script-arg2 ...

lfescript runs a script written in LFE. Periodt. 🌿

Types

lfescript:script_name() -> File

Types:

File = filename()

The script_name/0 function returns the name of the lfescript being executed. If the function is invoked outside the context of an lfescript, the behavior is undefined. πŸ‘€ Undefined is not a drill, bestie.

πŸ’… EXAMPLE πŸ’…

Here follows an example script.

$ cat factorial
#! /usr/bin/env lfescript
;; -*- mode: lfe -*-
;;! -smp enable -sname factorial -mnesia debug verbose

(defun main
  ([(list string)]
   (try
       (let* ((n (list_to_integer string))
              (f (fac n)))
         (lfe_io:format "factorial ~w = ~w\n" (list n f)))
     (catch
       ((tuple _ _ _) (usage)))))
  ([_] (usage)))

(defun fac
  ([0] 1)
  ([n] (* n (fac (- n 1)))))

(defun usage ()
  (lfe_io:format "usage: factorial integer\n" ()))

This example ate, honestly. πŸ”₯

The header of the LFE script is different from a normal LFE module. The first line is an interpreter line which invokes lfescript if the script is run as in the first command line above. If lfescript is explicitly invoked in the second command line above then this header line will be ignored. On the second or third line it is possible to give arguments to the emulator with the syntax:

;;! -smp enable -sname factorial -mnesia debug verbose

In the example the second line is an optional directive to Emacs which causes it to enter LFE mode when editing the script file.

The rest of the file contains LFE source code. It must always contain the function main/1. When the script is run this function will be called with a list of strings representing the arguments with which the script was called. It is possible to define, include and use macros in the source code.

The source code is checked and warnings and errors will be printed. If there are errors the script will not run and it will terminate with exit status 127. Otherwise the code will be interpreted. If the function main/1 returns successfully then the exit status for the script will be 0 but if an exception is raised then exit status will be 127. Big yikes on the 127, but at least you know. 😭

πŸ”₯ OPTIONS πŸ”₯

The following option is accepted by lfescript:

  • -s β€” Only perform a syntactic and semantic check of the script file. Warnings and errors (if any) are written to the standard output, but the script will not be run. The exit status will be 0 if there were no errors, and 127 otherwise. Lowkey the perfect little vibe check for your script. ✨

Unrecognised options are ignored. No drama, they just get ignored. 🫢

🌈 ENVIRONMENT VARIABLES 🌈

LFESCRIPT_EMULATOR β€” The command used to start the emulator. Default is erl. This can be useful for passing arguments into the emulator, for example:

LFESCRIPT_EMULATOR="erl -pa sune"

will add the directory sune to the code path. Obsessed with a little env var moment. πŸ’™

πŸ‘‘ SEE ALSO πŸ‘‘

lfe(1), lfe_guide(7) β€” go read those too, bestie, iykyk. πŸ‘‘πŸ¦‹

🌟 AUTHORS 🌟

Robert Virding. An absolute icon. πŸ’–


That's the whole lfescript(1) manual, dated 2013-2016 β€” xoxo, bye bestie! πŸ’…πŸ’–

πŸ“¦ where this page comes from