---
layout: ../Site.layout.js
---
# Common Lisp Strong Typing Example
Kent Pitman's condition system for ANSI Common Lisp is a deep, far ranging and still unexplored frontier of computer science. The fact that you can match up unknown *half-programs* as kent calls them that get executed *in the context they were signalled* when a condition is signalled remains the most revolutionary idea in terms of conditions. As to how important conditions are- If you remember the weirdly timeless/completely modern 1972 article by Terry Winograd, *Breaking The Complexity Barrier (Again)*, Terry briefly and somewhat apropos-nothing notes his belief that condition signalling and handling is the closest thing computers experience to human memory formation.
Deep. But my friend [Aleteoryx](https://labyrinth.zone/users/aleteoryx), who often hangs out on the show (23 hours from now, live, every week) at 000UTC Wednesdays (American Tuesday nights) on [anonradio](https://anonradio.net:8443/anonradio) was bemoaning their lack of powerful satisfaction in typed languages.
They wished - how great would it be if I could easily constrain an argument type to an integer from 0 to 20.
## Enter `etypecase` (find type case or error) in common lisp
```
(defun zero-to-20-only (x)
(etypecase x
((integer 0 20) :yes!)))
```
### (zero-to-20-only 20) case
```
CL-USER> (zero-to-20-only 20)
:YES!
```
### (zero-to-20-only 21) case
```
21 fell through ETYPECASE expression.
Wanted one of ((INTEGER 0 20)).
[Condition of type SB-KERNEL:CASE-FAILURE]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1004480003}>)
Backtrace:
0: (ZERO-TO-20-ONLY #<unavailable argument>)
1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (ZERO-TO-20-ONLY 21) #<NULL-LEXENV>)
2: (EVAL (ZERO-TO-20-ONLY 21))
--more--
```
# Satisfies only-on-tuesdays
They mentioned they wanted powerful and deeply arbitrary type constraint satisfaction. My silly response was a type which is only satisfied when the current weekday is Tuesday.
```
CL-USER> (defun only-true-on-tuesdays (x)
(declare (ignore x))
(equal 1 (nth-value 6 (get-decoded-time))))
(deftype available-on-tuesdays ()
`(satisfies only-true-on-tuesdays))
AVAILABLE-ON-TUESDAYS
CL-USER> (typep 'hey 'available-on-tuesdays)
T
CL-USER> (typecase 'anything
(available-on-tuesdays 'well-maybe))
WELL-MAYBE
```
Of course, Aleteoryx tried it and got NIL because I live about 18 hours in the future at the moment.
# Fin.
Sorry for the silly and light-hearted article. We dealt with
- [ANSI common lisp's `etypecase`](https://www.lispworks.com/documentation/HyperSpec/Body/m_tpcase.htm)
- Odd historical notes about computer science commentary on condition systems
- A type that requires a certain weekday
See everyone at the weekly show tomorrow. [Check the mastodon for last week's episode/archive for details](https://gamerplus.org/@screwlisp/114542771215751764).
[Discuss these kinds of types on the mastodon](https://gamerplus.org/@screwlisp/114577201539912869).