[Openmcl-devel] Extended-char is subtype of any other type

Renzo Orsini renzo.orsini at gmail.com
Thu Mar 2 23:30:11 PST 2017


Thanks for the explanation. In fact it is very clear and useful !

I misunderstood the type system of Common Lisp, thinking that the subtype relation were, like in other languages like ML, based the “structure” of type (i.e. syntax), not on their “semantics” (given the fact that the type as set is a semantic aspect). 

This now makes clear to me also the fact that “subtypep” is not an always an “authoritative” function, returning two values. When going into “semantics”, waters can become somewhat “murky” (and has also the undesirable side-effect of different behaviour for different implementations, but this is a well known thing!)

Thanks again.

Renzo

> On 2 Mar 2017, at 18:03 , R. Matthew Emerson <rme at acm.org> wrote:
> 
>> 
>> On Mar 2, 2017, at 2:58 AM, Renzo Orsini <renzo.orsini at gmail.com> wrote:
>> 
>> I found this strange behaviour when applying subtypep to extended-char:
>> 
>> $ ccl
>> Welcome to Clozure Common Lisp Version 1.11-r16635  (DarwinX8664)!
>> 
>> CCL is developed and maintained by Clozure Associates. For more information
>> about CCL visit http://ccl.clozure.com.  To enquire about Clozure's Common Lisp
>> consulting services e-mail info at clozure.com or visit http://www.clozure.com.
>> 
>> ? (subtypep 'extended-char 'bit)
>> T
>> T
>> ? (subtypep 'extended-char 'function)
>> T
>> T
>> ? 
>> … and similarly for many other types.
> 
> I'm not much of a language lawyer, but I think I can explain this.
> 
> Recall that a CL type is a set of objects.
> 
> In CCL, there is only one character type.  Thus, the set of objects denoted by the type (and character (not base-char)) contains no members.
> 
> The type that contains no objects is named nil.
> 
> (subtypep 'extended-char nil) => t, t
> (subtypep nil 'extended-char) => t, t
> 
> This shows that, on CCL, extended-char and nil are two names for the same thing (the empty set in this case).
> 
> The type nil is a subtype of every type.  See http://www.lispworks.com/documentation/HyperSpec/Body/t_nil.htm
> 
> Thus, when you write (subtypep 'extended-char 'bit), it is as if you are writing (subtypep nil 'bit).  And (subtypep nil x) is t, t for any type x.
> 
>> 
>> while the HyperSpec says (http://www.lispworks.com/documentation/HyperSpec/Body/t_extend.htm#extended-char):
>> 
>> The type extended-char is equivalent to the type (and character (not base-char)).
> 
> That entry also says:  The type extended-char might have no elements in implementations in which all characters are of type base-char.
> 
> I hope this explanation is correct and helpful.




More information about the Openmcl-devel mailing list