From b43d459fe02378982f94cd82ac9601acb7d05972 Mon Sep 17 00:00:00 2001 From: Tim Bradshaw Date: Fri, 13 Dec 2024 12:17:47 +0000 Subject: [PATCH] utilities: has valid-type-specifier-p --- README.md | 3 ++- VERSION | 2 +- utilities.lisp | 13 ++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c68d62..e41bdbc 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 () ...)`will bind `` to a fresh uninterned symbol with name `""`. `(with-names (( foo)) ...)` will bind `` 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`. diff --git a/VERSION b/VERSION index df5119e..3b68253 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.7.0 +8.8.0 diff --git a/utilities.lisp b/utilities.lisp index b812fe7..f40103b 100644 --- a/utilities.lisp +++ b/utilities.lisp @@ -8,7 +8,8 @@ #:parse-simple-body #:with-names #:thunk - #:thunk*)) + #:thunk* + #:valid-type-specifier-p)) (in-package :org.tfeb.hax.utilities) @@ -70,3 +71,13 @@ Optionally you can specify the name by giving a clause as (var ) (ignore ,)) ,@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))))