binding-arrows

2023-10-21

An implementation of threading macros based on binding anonymous variables

Upstream URL

github.com/phoe/binding-arrows

Author

Michał "phoe" Herda <phoe@disroot.org>

License

MIT
README

Binding Arrows

An implementation of threading macros based on binding anonymous variables.

Overview

This system implements binding threading macros - a kind of threading macros with different semantics than classical, Clojure core threading macros or their extension, swiss-arrows. Two Common Lisp implementations of those are arrows and arrow-macros.

This system is a fork of arrows with changes in semantics that make it impossible to merge back upstream.

What's the difference?

A binding threading macro implicitly binds a variable on each computation step, as opposed to working purely on the syntactic level like the classical threading macros.

This has three main implications:

  • Binding threading macros expand into a let* form.
    • Binding threading macros are nicer to read when macroexpanded.
    • Binding threading macros preserve intermediate binding steps for the debugger.
    • setf expansions are handled by explicit setf expanders for each macro.
  • Binding threading macros assume that it is possible to evaluate each form resulting from threading each computation step.
    • This also means that e.g. (-> foo (defun (bar) (1+ bar))) is going to expand into a correct defun form on a traditional threading macro implementation, but will fail on a binding implementation (e.g. this one).
  • Expansions of binding threading macros perform the aforementioned evaluation.
    • This means that e.g. (->> (loop) (or t)) is going to return t on a traditional (Clojure-like) implementation of threading macros, but will hang on a binding implementation (e.g. this one).

Contents

This system contains a package binding-arrows that exports the following symbols:

  • threading macros -> and ->>,
  • diamond threading macros -<> and -<>>,
  • short-circuiting threading macros some-> and some->>,
  • short-circuiting diamond threading macros some-<> and some-<>>,
  • conditional threading macros cond-> and cond->>,
  • conditional diamond threading macros cond-<> and cond-<>>,
  • inverted threading macro ->*,
  • named threading macro as->,
  • inverted named threading macro as->*.

All of the aforementioned threading macros name valid places for use in setf.

Loading

(ql:quickload :binding-arrows)

Testing

(asdf:test-system :binding-arrows)

Manual pages

License

MIT.

Dependencies (1)

  • hu.dwim.stefil

Dependents (2)

  • GitHub
  • Quicklisp