From: Raymond Toy
Subject: Looking inside a deftype?
Date: 
Message-ID: <4nvi5gxs89.fsf@rtp.ericsson.se>
Instead of the current flame war of Lisp vs. the hot language du jour
and everything else, here is a lisp question that I hope someone can
answer.

I've been using the nice series package with CMUCL.  To appease
CMUCL's nice compiler, variables must be initialized to the correct
type.  (The current version of series doesn't do this very well.)

I've modified series so that it initializes variables with the correct 
types.  However, my question is what if I use a deftype to create my
own aliases of common types?

For example:

	(deftype complex-type () '(complex single-float))

or

	(deftype my-vec () '(simple-array single-float (4)))

Is there a way that I can "look" inside the type of my-vec to find out 
that it is really a (simple-array single-float (4))?  subtypep can
tell me that it's a (simple-array single-float), but I can't seem to
find any way to get the length out of it.

I'm looking for a function that can take any type and return the
"canonical" type like so:

	(canonical-type 'my-vec) => '(simple-array single-float (4))

	(canonical-type 'complex-type) => '(complex single-float)


Thanks for any pointers,

Ray

From: Pierpaolo Bernardi
Subject: Re: Looking inside a deftype?
Date: 
Message-ID: <5jkreh$17so$1@pania.unipi.it>
Raymond Toy (···@rtp.ericsson.se) wrote:

...

: I've been using the nice series package with CMUCL.  To appease
: CMUCL's nice compiler, variables must be initialized to the correct
: type.  (The current version of series doesn't do this very well.)

: I've modified series so that it initializes variables with the correct 
: types.  However, my question is what if I use a deftype to create my
: own aliases of common types?

: For example:

: 	(deftype complex-type () '(complex single-float))

: or

: 	(deftype my-vec () '(simple-array single-float (4)))

: Is there a way that I can "look" inside the type of my-vec to find out 
: that it is really a (simple-array single-float (4))?  subtypep can
: tell me that it's a (simple-array single-float), but I can't seem to
: find any way to get the length out of it.

: I'm looking for a function that can take any type and return the
: "canonical" type like so:

: 	(canonical-type 'my-vec) => '(simple-array single-float (4))

: 	(canonical-type 'complex-type) => '(complex single-float)

If all else fails, you can try and shadow deftype with a version which
stores somewhere the type expression (e.g. on the typename's plist).

: Ray

Pierpaolo.
From: Raymond Toy
Subject: Re: Looking inside a deftype?
Date: 
Message-ID: <4nhggxevzr.fsf@rtp.ericsson.se>
>>>>> "Pierpaolo" == Pierpaolo Bernardi <········@cli.di.unipi.it> writes:

    Pierpaolo> Raymond Toy (···@rtp.ericsson.se) wrote: ...

    Pierpaolo> If all else fails, you can try and shadow deftype with
    Pierpaolo> a version which stores somewhere the type expression
    Pierpaolo> (e.g. on the typename's plist).

Thanks for the hint.  I guess this will work for all Lisp systems.

For CMUCL, you can do the following to get the underlying type out of
a deftype:

	(kernel:type-specifier (c::specifier-type type))

Ray
From: Dmitri Ivanov
Subject: Re: Looking inside a deftype?
Date: 
Message-ID: <01bc5001$7e626be0$LocalHost@divanov.aha.ru>
Raymond Toy <···@rtp.ericsson.se> wrote in article
<··············@rtp.ericsson.se>...
 
> ....  However, my question is what if I use a deftype to create my
> own aliases of common types?
> 
> For example:
> 
> 	(deftype complex-type () '(complex single-float))
> 
> or
> 
> 	(deftype my-vec () '(simple-array single-float (4)))
> 
> Is there a way that I can "look" inside the type of my-vec to find out 
> that it is really a (simple-array single-float (4))?  

IMHO, upgraded-array-element-type and upgraded-complex-part-type might do.
Both return the most specialized type of components. In ACLW, I had

> (upgraded-array-element-type 'my-vec)
T

> (upgraded-complex-part-type 'complex-type)
T

Then you shoud construct "canomical" type by yourself.

-- 
Sincerely,
                  Dmitri Ivanov
                  ·······@aha.ru
From: R. Toy
Subject: Re: Looking inside a deftype?
Date: 
Message-ID: <3362AD17.34AE8EB2@mindspring.com>
Dmitri Ivanov wrote:
> 
> Raymond Toy <···@rtp.ericsson.se> wrote in article
> <··············@rtp.ericsson.se>...
> 
> > ....  However, my question is what if I use a deftype to create my
> > own aliases of common types?
> >
> > For example:
> >
> >       (deftype complex-type () '(complex single-float))
> >
> > or
> >
> >       (deftype my-vec () '(simple-array single-float (4)))
> >
> > Is there a way that I can "look" inside the type of my-vec to find out
> > that it is really a (simple-array single-float (4))?
> 
> IMHO, upgraded-array-element-type and upgraded-complex-part-type might do.
> Both return the most specialized type of components. In ACLW, I had
> 
> > (upgraded-array-element-type 'my-vec)
> T
> 
> > (upgraded-complex-part-type 'complex-type)
> T
> 

I think this is totally wrong for what I want.  You are asking for an
array whose elements are of type 'my-vec.  I don't know of ANY Lisp that
actually has a special representation of an array whose elements are
4-element simple arrays of floats.


-- 
---------------------------------------------------------------------------
----> Raymond Toy	····@mindspring.com
                        http://www.mindspring.com/~rtoy