2016-05-10 04:25:50 +00:00
|
|
|
#lang racket/base
|
|
|
|
;; Misc support routines not (yet) provided by racket itself
|
|
|
|
|
|
|
|
(provide non-object-struct?
|
|
|
|
struct-type-name
|
2016-05-12 16:15:31 +00:00
|
|
|
struct-type-constructor-arity
|
2016-05-10 04:25:50 +00:00
|
|
|
struct->struct-type)
|
|
|
|
|
|
|
|
(require (only-in racket/class object?))
|
|
|
|
|
|
|
|
;; Any -> Boolean
|
|
|
|
;; Racket objects are structures, so we reject them explicitly for
|
|
|
|
;; now, leaving them opaque to unification.
|
|
|
|
(define (non-object-struct? x)
|
|
|
|
(and (struct? x)
|
|
|
|
(not (object? x))))
|
|
|
|
|
|
|
|
;; struct-type -> Symbol
|
|
|
|
;; Extract just the name of the given struct-type.
|
|
|
|
(define (struct-type-name st)
|
|
|
|
(define-values (name x2 x3 x4 x5 x6 x7 x8) (struct-type-info st))
|
|
|
|
name)
|
|
|
|
|
2016-05-12 16:15:31 +00:00
|
|
|
;; StructType -> Natural
|
|
|
|
(define (struct-type-constructor-arity st)
|
|
|
|
(define-values (x1 arity x3 x4 x5 x6 x7 x8) (struct-type-info st))
|
|
|
|
arity)
|
|
|
|
|
2016-05-10 04:25:50 +00:00
|
|
|
;; Structure -> StructType
|
|
|
|
;; Errors when given any struct that isn't completely transparent/prefab.
|
|
|
|
(define (struct->struct-type p)
|
|
|
|
(define-values (t skipped?) (struct-info p))
|
|
|
|
(when skipped? (error 'struct->struct-type "Cannot reflect on struct instance ~v" p))
|
|
|
|
t)
|
2016-05-12 16:15:31 +00:00
|
|
|
|