vault

2026-11-29

A vault of functions

Upstream URL

github.com/HectareaGalbis/vault

Author

Héctor Galbis Sanchis

License

MIT
README

Vault

Welcome to Vault! :D

Introduction

A vault maps symbols with functions. It is like a different namespace for functions.

¿But why?

This is needed if we want to name new functions or variables without polluting a package. This is handy for making complex macros where the user could define an extension for such macro and give it a name.

Using Vault

First we create a vault using vault:make-vault:

(defvar super-vault (make-vault))
;; Returns
SUPER-VAULT

Now super-vault is like a new namespace for functions.

We can check if an object is a vault with vault:vaultp:

(vaultp super-vault)
;; Returns
T

Defining functions

We define a new function using vault:vault-defun:

(vault-defun super-vault super-function (x)
  "A super function"
  (+ x 10))
;; Returns
SUPER-FUNCTION

Now super-function is a function defined inside the vault super-vault.

We can retrieve a function from a vault using vault:vault-function:

(vault-function super-vault 'super-function)
;; Returns
#<FUNCTION (LABELS SUPER-FUNCTION) {B800DEE7BB}>

If the function does not exist in the vault NIL is returned:

(vault-function super-vault 'non-existent-function)
;; Returns
NIL

Lastly, we can update a function using vault:vault-function and setf:

(setf (vault-function super-vault 'super-function) (lambda (x) (+ x 7)))
;; Returns
#<FUNCTION (LAMBDA (X)) {B800DEEA6B}>

Calling functions

We can call functions directly with vault:vault-funcall or vault:vault-apply:

(vault-funcall super-vault 'super-function 3)
;; Returns
10
(vault-apply super-vault 'super-function '(3))
;; Returns
10

Docstrings

We can use documentation to retrieve or attach a docstring to a vault function.

(vault-defun super-vault foo ()
  "FOO DOCSTRING"
  "FOO")

(documentation 'foo super-vault)
;; Returns
"FOO DOCSTRING"
(setf (documentation 'foo super-vault) "ANOTHER FOO DOCSTRING")
(documentation 'foo super-vault)
;; Returns
"ANOTHER FOO DOCSTRING"

Reference

Function: vault:make-vault ()

Creates a vault

Function: vault:vault-apply (vault name &rest args)

Apply the function NAME from VAULT with ARGS.
If function does not exist in VAULT, an error of type FUNCTION-NOT-FOUND-ERROR is signaled.

Macro: vault:vault-defun (vault name (&rest args) &body body)

Define a function named NAME and insert or update it in the VAULT.
The documentation is attached as a documentation string to the VAULT
(as kind VAULT) and to the function object.

Function: vault:vault-fmakunbound (vault name)

Unbind the function NAME from VAULT.
Returns true if there was such a function, of false otherwise.

Function: vault:vault-funcall (vault name &rest args)

Call the function NAME from VAULT with ARGS.
If function does not exist in VAULT, an error of type FUNCTION-NOT-FOUND-ERROR is signaled.

Function: vault:vault-function (vault name)

Retrieve the function NAME from VAULT if it exists. NIL otherwise.

Generic function: vault:vault-function-not-found-name(condition)

Undocumented

Function: vault:vaultp (vault)

Check if an object is a vault.

Class: vault:vault-function-not-found-error

Indicates that a function was not found in the vault.
  • Direct slots:

    • vault::name
      • Allocation: :instance
      • Readers: vault:vault-function-not-found-name
  • Metaclass: sb-pcl::condition-class

  • Precedence list: vault:vault-function-not-found-error, error, serious-condition, condition, sb-pcl::slot-object, t

  • Direct superclasses: error

Dependencies (0)

    Dependents (1)

    • expanders
    • GitHub
    • Quicklisp