From: Anton K. <an...@sw...> - 2011-08-11 20:34:05
|
Gabriel Dos Reis <gd...@in...> writes: > We do not use directly TYPEP or SUBTYPEP. But, we do rely > heavily on function type proclamations involving those type specifiers. > Is such usage also not-recommended? Everything is fine unless you really need 'STRING for some of your declarations (in the sense of accepting/returning both base-strings and non-base strings and not being sure). Note that you may be working with base-strings unwittingly, even if you are not requesting their creation anywhere in your code: (type-of (symbol-name 'list)) => (SIMPLE-BASE-STRING 4) Default stream element type for SBCL's OPEN is BASE-CHAR too, so another possibly-unexpected source of base-strings in your code is READ-LINE. The declaration using a type that expands to STRING is the right one for code that may receive a base-string; if you replace it with a type expanded to (VECTOR CHARACTER), then base-string will cause a failure (btw, for any level of SAFETY but the most reckless one, SBCL will normally detect a type error in this case, instead of doing something dangerous). > OK. So, just to make sure I understand: it is OK to use the type > specifiers as long > as they expand to (VECTOR something), but not to the type specifier STRING > or SIMPLE-STRING. Is that correct? Yes. BASE-STRING and SIMPLE-BASE-STRING are fine too: their specialization is fixed and they aren't "hairy", because there is nothing like VERY-VERY-BASE-STRING specialized for some VERY-VERY-BASE-CHAR subset of possible BASE-CHARs. For /declarations/, any type (be it deftyped or predefined) is acceptable, so when you've figured out the right type to declare, feel free to use a deftype'd name. -- Regards, Anton Kovalenko +7(916)345-34-02 | Elektrostal' MO, Russia |