[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

user type names

My very rough draft manual does not specify any way for a user to define
a type name in terms of the primitive types, which seems like a serious
omission.  Perhaps this has already been fixed?  If not, I propose
          (DEFTYPE name (args ...) expansion)
E.g. instead of building in unsigned-byte, you could do
          (deftype unsigned-byte (s) (integer 0 (- (expt 2 s) 1)))
The need for this should be obvious, even though it doesn't exist in
Lisp now.  Basically Common Lisp is going to force you to specify types
more often that older Lisps if you want efficiency, so you need a way of
abbreviating things for brevity, clarity, and maintainability.  I'd hate
to have to write
          (map #'+ (the (vector (integer 0 (- (expt 2 32) 1)) 64) x)
                   (the (vector (integer 0 (- (expt 2 32) 1)) 64) y))
I can barely find the actual vectors being used!

This also allows you define lots of the builtin types yourself, which
seems more elegant than singling out signed-byte as worthy of inclusion.
Also, it provides a facility that exists in languages such as Pascal.

Now, how would you implement deftypes?  A macro mechanism seems like the
appropriate thing.  E.g. when the interpreter or compiler finds a type
expression it can't grok, it would do
          (funcall (get (car expr) 'type) expr)
and use the returned frob as the type.