Skip to content
/ l-el Public

l.el is a series of lisp functions and macros in order to make emacs-lisp more modern and functional

License

Notifications You must be signed in to change notification settings

viglioni/l-el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

l.el - Modern Functional Programming Utilities for Emacs Lisp

Table of Contents

Overview

Check the latest release code.

l.el provides a comprehensive modern functional programming approach to writing Emacs Lisp, drawing inspiration from Common Lisp, Haskell, and Elixir. This library transforms Emacs Lisp into a more expressive functional programming language with advanced features including automatic currying, sophisticated pattern matching, type systems, syntax transformations, and specialized development tools.

Supported Emacs Versions

Emacs VersionLinuxmacOS IntelmacOS ARM64
26.3N/A
27.2N/A
28.2
29.4
30.1

All versions are tested on every push via GitHub Actions CI.

This lib is currently written on macOS M4 Max with Emacs 29.4, only QAed in this setup.

;; -*- l-syntax: t; -*-

@doc "A function that returns the nth Fibonacci number.
This function grows exponentially and demonstrates direct value matching."
(ldef fib 0 -> 0)
(ldef fib 1 -> 1)
(ldef fib (n :integer) ->
      (+ (fib (- n 1))
         (fib (- n 2))))

@doc "This function calculates delta in a quadratic function
and demonstrates automatic currying capabilities."
(ldef delta (a :number) (b :number) (c :number) ->
      (- (* b b) (* 4 a c)))

;; Multiple calling styles with automatic currying:
((((delta) 1) 2) 3)  ;; Chained partial application
(delta 1 2 3)        ;; Direct application
(funcall (delta 1 2) 3) ;; Partial with funcall

@doc "Sum function with rest parameters for variadic arguments."
(ldef sum (nums :rest) -> (apply '+ nums))
(sum 1 2 3 4 5)      ;; => 15

@doc "Greeting function with direct value matching."
(ldef greet "Alice" -> "Hello, Alice!")
(ldef greet (name :string) -> (concat "Hi, " name "!"))
(greet "Alice")      ;; => "Hello, Alice!"
(greet "Bob")        ;; => "Hi, Bob!"

Features

Core Pattern Matching & Dispatch

  • **Direct value matching** - Match literal values directly: numbers, strings, keywords, quoted symbols, nil, t, vectors, and lists
  • **Type-based dispatch** - Comprehensive type system with primitive types, category types, and parameterized types (:instance_of, :list_of)
  • **Automatic currying** - Functions curry automatically when called with fewer arguments than defined
  • **Lexicographic specificity** - Intelligent pattern ordering ensures most specific patterns match first

Functional Programming Primitives

  • **Arrow syntax** - Clean, modern syntax with -> for lambdas (l) and function definitions (ldef)
  • **Partial application** - lpartial for creating partially applied functions
  • **Placeholder substitution** - Elegant __ placeholder for concise anonymous functions
  • **Function composition** - lcomp and lpipe for composing transformations

Developer Experience

  • **Enhanced major mode** - l-mode with specialized syntax highlighting for ldef functions, calls, and arrows
  • **Elixir-style documentation** - @doc macro for beautiful, discoverable function documentation
  • **Syntax transformation** - with-l and l-syntax enable natural curried function call syntax without explicit funcall
  • **Type predicates** - Extensive type checking with 30+ built-in predicates plus parameterized types

Advanced Features

  • **Rest parameters** - Variadic functions with (param :rest) syntax
  • **Generic function management** - Tools for inspecting and cleaning up ldef functions
  • **Custom exceptions** - Structured error handling with l-raise
  • **Specialized loading** - l-require with automatic l-syntax processing

Check changelog and breaking changes for version history.

Usage

This package is not on MELPA/ELPA (yet?), but you can install via use-package/straight:

(use-package l
  ;; clones latest release
  :straight (l :type git :host github :repo "viglioni/l-el" :branch "latest-release")
  :mode ("\\.el\\'" . l-mode) ;; Enhanced syntax highlighting
  :custom
  (l-syntax t) ;; Optional: globally enable l-syntax transformations
  :config
  (l-syntax-advices) ;; Enable automatic syntax transformation
  ;; ...
  )

Or clone this repository, add l.el to your load path and require it:

(require 'l)

Configuration

The l-syntax variable controls syntax transformation behavior and can be configured in multiple ways:

***Global Configuration:***

(setq l-syntax t)
(l-syntax-advices)  ; Enable automatic transformation for evaluation functions

***File-local Configuration (Property Line):***

;; -*- l-syntax: t; -*-

***File-local Configuration (Local Variables):***

;; Local Variables:
;; l-syntax: t
;; End:

When enabled, l-syntax automatically wraps expressions in with-l during eval-last-sexp, eval-region, eval-buffer, load-file, and load operations, enabling natural curried function syntax without explicit with-l wrapping.

API Reference

See API Reference for the complete documentation of all functions, macros, and variables.

For breaking changes between versions, see Breaking Changes.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Development

For information on contributing, running tests, and the release process, see Development Guide.

About

l.el is a series of lisp functions and macros in order to make emacs-lisp more modern and functional

Resources

License

Stars

Watchers

Forks

Packages

No packages published