I've written a describe function for PLT Scheme - because I always
liked it in Common Lisp. I'll put it on PLaneT eventually, but was
wondering if anyone had suggestions for what to include. Data types
that are there now that I'm pretty comfortable with are: Booleans,
numbers, strings, byte strings, characters, symbols, regular
expressions, byte regular expressions, keywords, lists, pairs (improper
lists), mutable lists, mutable pairs (improper mpairs), vectors, boxes,
hashes, procedures, and void.<br>
<br>I may have gone a bit overboard with giving the names of integers
(up to 10^102), but the Symbolics Common Lisp describe function did it
and I always liked showing it off. So, I included it. But, it might
make sense to limit it to fixums just to keep the name from getting so
long.<br>
<br>I'm pretty happy with procedure descriptions with the number of
positional arguments and required and optional keywords. (I still need
to handle the case of the optional keywords list being #f - that is,
allow any keyword.) I'm curious about whether a primitive closure is
different from a primitive procedure - for example, can you get the
result arity for a primitive closure like you can for a primitive
procedure. And, what is a example of a primitive closure so I can
include a test for it?<br>
<br>I've included recursively describing boxes and hashes. It shouldn't
be a problem for boxes, but hash descriptions could get rather long
when I include descriptions of the key values. Would it make sense to
have a recursive? arguments to control this? If recursive? is
implemented should it also apply to lists, vectors, etc? I'm concerned
about inundating the user with detail where it isn't needed. [Maybe the
best thing is to limit recursive descriptions to boxes.]<br>
<br>Structs and objects are somewhat more problematic. If a struct
responds to struct?, I can get some details with struct->vector. So,
I am currently recursively describing the field details (by field
number) for these. As far as I can tell, completely opaque structured
(i.e., those that return #f for struct?) will give me the 'name' of the
structure type by using object-name. Any suggestions for describing
structs and objects (and classes) would be welcome.<br>
<br>What other first-class data object would be useful to include
(parameters, which get described as procedures now, modules, units,
signatures, processes, ...)?<br><br>Thoughts, suggestions, comments, etc are welcome.<br>
<br>The message with describe.ss attached was too big to post (I can send it separately if anyone wants to play with it), but here is some spew of the describe-test.ss file:<br><br>--- Booleans ---<br>#t is the Boolean true<br>
#f is the Boolean false<br><br>--- Numbers ---<br>+inf.0 is positive infinity<br>-inf.0 is negative infinity<br>+nan.0 is an inexact positive real number<br>
0 is the exact integer fixnum zero<br>3628800 is the exact positive integer fixnum three million six hundred twenty-eight thousand eight hundred<br>815915283247897734345611269596<div id=":2m" class="ii gt">115894272000000000
is an exact positive integer eight hundred fifteen quattuordecillion
nine hundred fifteen tredecillion two hundred eighty-three duodecillion
two hundred forty-seven undecillion eight hundred ninety-seven
decillion seven hundred thirty-four nonillion three hundred forty-five
octillion six hundred eleven septillion two hundred sixty-nine
sextillion five hundred ninety-six quintillion one hundred fifteen
quadrillion eight hundred ninety-four trillion two hundred seventy-two
billion<br>
-32636611329915909373824450783844635770880000000000
is an exact negative integer minus thirty-two quindecillion six hundred
thirty-six quattuordecillion six hundred eleven tredecillion three
hundred twenty-nine duodecillion nine hundred fifteen undecillion nine
hundred nine decillion three hundred seventy-three nonillion eight
hundred twenty-four octillion four hundred fifty septillion seven
hundred eighty-three sextillion eight hundred forty-four quintillion
six hundred thirty-five quadrillion seven hundred seventy trillion
eight hundred eighty billion<br>
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 is an exact positive integer value whose absolute value is >= 10^102<br>
3628800/39916801 is an exact positive rational number with a numerator of 3628800 and a denominator of 39916801<br>-1+3i is an exact complex number whose magnitude is 3.1622776601683795<br>0.0 is an inexact integer zero<br>
3628800.0 is an inexact positive integer<br>8.159152832478977e+047 is an inexact positive integer<br>3.1622776601683795 is an inexact positive real number<br>0+3.1622776601683795i is an inexact positive imaginary number<br>
3.1622776601683795+3.1622776601683795i is an inexact complex number whose magnitude is 4.47213595499958<br><br>--- Strings ---<br>"abc" is an immutable string of length 3<br>"123" is a mutable string of length 3<br>
<br>--- Byte Strings ---<br>#"abc" is an immutable byte string of length 3<br>#"012" is a mutable byte string of length 3<br><br>--- Characters ---<br>#\a is the character whose code-point number is 97(#x61) and general category is 'll (letter, lowercase)<br>
#\A is the character whose code-point number is 65(#x41) and general category is 'lu (letter, uppercase)<br>#\0 is the character whose code-point number is 48(#x30) and general category is 'nd (number, decimal digit)<br>
#\( is the character whose code-point number is 40(#x28) and general category is 'ps (punctuation, open)<br><br>--- Symbols ---<br>abc is the interned symbol<br>|(a + b)| is the interned symbol<br>g1121 is an uninterned symbol<br>
<br>--- Regular Expressions ---<br>#rx"Ap*le" is a regular expression in regexp format<br>#px"Ap*le" is a regular expression in pregexp format<br><br>--- Byte Regular Expressions ---<br>#rx#"Ap*le" is a byte regular expression in regexp format<br>
#px#"Ap*le" is a byte regular expression in pregexp format<br><br>--- Keywords ---<br>#:key is the keyword<br><br>--- Lists and Pairs ---<br>(this is a proper list) is a proper immutable list of length 5<br>(this is an improper . list) is an improper immutable list<br>
((this . is) (also . a) (proper . list)) is a proper immutable list of length 3<br><br>--- Mutable Lists and Pairs ---<br>{this is a proper list} is a proper mutable list of length 5<br>{this is an improper . list} is an improper mutable list<br>
{(this . is) (also . a) (proper . list)} is a proper mutable list of length 3<br><br>--- Vectors ---<br>#(1 2 3) is an immutable vector of length 3<br><br>--- Boxes ---<br>#&12 is a box containing 12, 12 is the exact positive integer fixnum twelve<br>
#&#&a is a box containing #&a, #&a is a box containing a, a is the interned symbol<br>#&3.1622776601683795 is a box containing 3.1622776601683795, 3.1622776601683795 is an inexact positive real number<br>
<br>--- Hashes ---<br>#hash((c . 16) (b . 14) (a . 12)) is an immutable hash table and that uses equal? to compare keys<br> c : 16, 16 is the exact positive integer fixnum sixteen<br> b : 14, 14 is the exact positive integer fixnum fourteen<br>
a : 12, 12 is the exact positive integer fixnum twelve<br>#hasheq((c . c) (b . b) (a . a)) is an immutable hash table and that uses eq? to compare keys<br> c : c, c is the interned symbol<br> b : b, b is the interned symbol<br>
a : a, a is the interned symbol<br>#hasheqv((c . #\c) (b . #\b) (a . #\a)) is an immutable hash table and that uses eqv? to compare keys<br> c : #\c, #\c is the character whose code-point number is 99(#x63) and general category is 'll (letter, lowercase)<br>
b : #\b, #\b is the character whose code-point number is 98(#x62) and general category is 'll (letter, lowercase)<br> a : #\a, #\a is the character whose code-point number is 97(#x61) and general category is 'll (letter, lowercase)<br>
#hash((b . 14) (a . 12) (c . 16)) is a mutable hash table and that uses equal? to compare keys<br> b : 14, 14 is the exact positive integer fixnum fourteen<br> a : 12, 12 is the exact positive integer fixnum twelve<br>
c : 16, 16 is the exact positive integer fixnum sixteen<br>
#<hash> is a mutable hash table that holds its keys weakly and that uses equal? to compare keys<br> c : 16, 16 is the exact positive integer fixnum sixteen<br> b : 14, 14 is the exact positive integer fixnum fourteen<br>
a : 12, 12 is the exact positive integer fixnum twelve<br><br>--- Procedures ---<br>#<procedure:car> is a primitive procedure named car that accepts 1 argument and returns 1 result<br>#<procedure:open-output-file>
is a procedure named open-output-file that accepts 1 argument plus
optional keyword arguments #:exists and #:mode<br>
#<procedure:current-input-port> is a primitive procedure named current-input-port that accepts 0 or 1 arguments and returns 1 result<br>#<procedure:...describe-test.ss:133:10> is a procedure named ...describe-test.ss:133:10 that accepts 1 argument<br>
<br>--- Void ---<br>#<void> is void<br><br>--- Structures ---<br>#(struct:transparent-struct a b c) is a structure of type transparent-struct<br> 1 : a, a is the interned symbol<br> 2 : b, b is the interned symbol<br>
3 : c, c is the interned symbol<br><br>--- Other Named Things ---<br>#<opaque-struct> is an object of type opaque-struct<br><font color="#888888"><br>Doug</font></div>