Skip to content

Commit b43d459

Browse files
committed
utilities: has valid-type-specifier-p
1 parent 07f64ea commit b43d459

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ It originated as part of a lambda list parser, and betrays that heritage to some
18711871
There arguably should be spread versions of many of these combinators, so if you have a list of predicates you could say, for instance `(all-of* preds)` rather than `(apply #'all-of preds)`. There might be in future.
18721872

18731873
### Package, module, dependencies
1874-
`spam` lives in `org.tfeb.hax.spam` and provides `:org.tfeb.hax.spam`. It requires `simple-loops` and will attempt to load it if `require-module` is present.
1874+
`spam` lives in `org.tfeb.hax.spam` and provides `:org.tfeb.hax.spam`. It requires `utilities` and `simple-loops` and will attempt to load them if `require-module` is present.
18751875

18761876
## Metatronic macros
18771877
Or, recording angel. From an idea by Zyni.
@@ -2456,6 +2456,7 @@ Here is what it currently provides.
24562456
- `with-names` binds variables to uninterned symbols with the same name by default: `(with-names (<foo>) ...)`will bind `<foo>` to a fresh uninterned symbol with name `"<FOO>"`. `(with-names ((<foo> foo)) ...)` will bind `<foo>` to a fresh uninterned symbol with name `"FOO"`.
24572457
- `thunk` makes anonymous functions with no arguments: `(thunk ...)` is `(lambda () ...)`.
24582458
- `thunk*` makes anonymous functions which take an arbitrary number of arguments and ignore them all.
2459+
- `valid-type-specifier-p` attempts to answer the question 'is something a valid type specifier?'. It does this by asking `subtypep` if it's a subtype of `t`, on the assumption that *any* valid type specifier should be a recognizable subtype of `t`. There is an optional second argument which is an environment object: using this lets it answer the question for the compilation environment: see [this CLHS issue](https://www.lispworks.com/documentation/HyperSpec/Issues/iss334.htm "Issue `SUBTYPEP-ENVIRONMENT:ADD-ARG` Summary").
24592460

24602461
### Package, module
24612462
The utilities live in and provide `:org.tfeb.hax.utilities`.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.7.0
1+
8.8.0

utilities.lisp

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#:parse-simple-body
99
#:with-names
1010
#:thunk
11-
#:thunk*))
11+
#:thunk*
12+
#:valid-type-specifier-p))
1213

1314
(in-package :org.tfeb.hax.utilities)
1415

@@ -70,3 +71,13 @@ Optionally you can specify the name by giving a clause as (var <string-designato
7071
(declare (dynamic-extent ,<args>)
7172
(ignore ,<args>))
7273
,@body)))
74+
75+
(defun valid-type-specifier-p (thing &optional (environment nil))
76+
"Is THING a valid type specifier in ENVIRONMENT?
77+
78+
This works by using SUBTYPEP and catching the error, and therefore
79+
assumes that any type specifier is a recognizable subtype of T. If
80+
that's not true it will perhaps fail.
81+
82+
Yes, having to catch the error is horrible: this is a deficiency of CL."
83+
(values (ignore-errors (subtypep thing t environment))))

0 commit comments

Comments
 (0)