Typed Lisp, A Primer
BRANK
Checking the type of inputs is tedious and so I guessed it could be done using macros and advice. Looking at Typed Racket for inspiration, the following fictitious syntax would add advice to f that checks the optional arguments xᵢ have type σᵢ and the mandatory positional arguments have type τᵢ according to position, and the result of the computation is of type τ. To the best of my knowledge, no one had done this for Emacs Lisp —I don't know why.(declare-type 'f ((:x₁ σ₁) … (:xₘ σₘ)) (τ₁ … τₙ τ)) To modify a variable, or function, we may simply redefine it; but a much more elegant and powerful approach is to “advise” the current entity with some new behaviour. In our case of interest, we will advise functions to check their arguments before executing their bodies.Below is my attempt: declare-type. Before you get scared or think it's horrendous, be charitable and note that about a third of the following is documentation and a third is local declarations.(cl-defmac…