Джерело:
Common Lisp Tips
Дата публікації:
28/02/2013 04:20
Постійна адреса новини:
http://www.vsinovyny.com/8323838
28/02/2013 04:20 // Common Lisp Tips
deftype can be used to create user-defined types that expand into built-in types. For example:
(deftype octet-vector (length) `(simple-array (unsigned-byte 8) (,length)))
Given this deftype, in a type context, (octet-vector 32) expands into (simple-array (unsigned-byte 8) (32)), or a one-dimensional octet array of length 32.
Lambda lists for deftype are very similar to lambda lists for defmacro, with an important difference: where optional arguments to defmacro with no initialization form default to nil, the default value in deftype is the symbol *. The deftype above could be rewritten to take advantage of this:
(deftype octet-vector (&optional length) `(simple-array (unsigned-byte 8) (,length)))
Now, in a type context, a plain octet-vector expands into (simple-array (unsigned-byte 8) (*)), or a one-dimensional octet array of indeterminate length, and (octet-vector 32) expands into (simple-array (unsigned-byte 8) (32)).
For more information, see section 3.4.8, Deftype Lambda Lists.
| « |
Наступна новина з архіву How do I convert an integer to a list of bits? |
Попередня новина з архіву Trying again with with-simple-restart |
» | |
|
|
||||