Skip to content

Commit

Permalink
utilities: has valid-type-specifier-p
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeb committed Dec 13, 2024
1 parent 07f64ea commit b43d459
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ It originated as part of a lambda list parser, and betrays that heritage to some
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.

### Package, module, dependencies
`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.
`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.

## Metatronic macros
Or, recording angel. From an idea by Zyni.
Expand Down Expand Up @@ -2456,6 +2456,7 @@ Here is what it currently provides.
- `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"`.
- `thunk` makes anonymous functions with no arguments: `(thunk ...)` is `(lambda () ...)`.
- `thunk*` makes anonymous functions which take an arbitrary number of arguments and ignore them all.
- `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").

### Package, module
The utilities live in and provide `:org.tfeb.hax.utilities`.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.7.0
8.8.0
13 changes: 12 additions & 1 deletion utilities.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#:parse-simple-body
#:with-names
#:thunk
#:thunk*))
#:thunk*
#:valid-type-specifier-p))

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

Expand Down Expand Up @@ -70,3 +71,13 @@ Optionally you can specify the name by giving a clause as (var <string-designato
(declare (dynamic-extent ,<args>)
(ignore ,<args>))
,@body)))

(defun valid-type-specifier-p (thing &optional (environment nil))
"Is THING a valid type specifier in ENVIRONMENT?
This works by using SUBTYPEP and catching the error, and therefore
assumes that any type specifier is a recognizable subtype of T. If
that's not true it will perhaps fail.
Yes, having to catch the error is horrible: this is a deficiency of CL."
(values (ignore-errors (subtypep thing t environment))))

0 comments on commit b43d459

Please sign in to comment.