Skip to content

Commit

Permalink
std/misc/rtd: add type=?
Browse files Browse the repository at this point in the history
  • Loading branch information
fare committed Nov 3, 2023
1 parent d4794cc commit 027572e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions doc/reference/std/misc/rtd.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ type object.
```
:::

## type=?
``` scheme
(type=? typ1 type2) -> bool
typ1 := type object
typ2 := other type object
```

Returns true if the two type objects have the same `type-id`.
This is the preferred equality predicate for types.
`eq?` and `eqv?` should also work, but at present
`equal?` seems to be broken.

::: tip Examples:
``` scheme
> (defstruct a ())
> (defclass b ())
> (type-id a::t)
#:a::t45
> (type-id b::t)
#:b::t49
> (type=? a::t a::t)
#t
> (type=? a::t b::t)
#f
```
:::

## type-name
``` scheme
(type-name typ) -> type name | error
Expand Down
5 changes: 4 additions & 1 deletion src/std/misc/rtd.ss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;;; safe type descriptor accessors
(import :std/error)
(export (rename: checked-object-type object-type)
type? type-id type-name type-super
type? type=? type-id type-name type-super
type-descriptor?
(rename: checked-type-descriptor-mixin type-descriptor-mixin)
(rename: checked-type-descriptor-fields type-descriptor-fields)
Expand Down Expand Up @@ -52,3 +52,6 @@
(defcheck-type-descriptor checked-type-descriptor-ctor type-descriptor-ctor)
(defcheck-type-descriptor checked-type-descriptor-slots type-descriptor-slots)
(defcheck-type-descriptor checked-type-descriptor-methods type-descriptor-methods)

(def (type=? x y)
(eq? (type-id x) (type-id y)))

0 comments on commit 027572e

Please sign in to comment.