I am studying Common Lisp and I would like to know if by using the :type slot in a defstruct, I am making the code more efficient?
In "Paradigms of Artificial Intelligence Programming", Peter Norvig wrote that with the appropriate declarations you can make Common Lisp programs as efficient as C programs. He writes that run-time type-checking is slow in Common Lisp but if you add declarations then you eliminate run-time checks.
So, I am aware that using the :type slot is analogous to a declaration of a variable so I would like to know if using :type makes the code faster (ie eliminates run time checks).
Here are some examples:
(defstruct matrix
rows
columns
contents)
Here is the version with :type:
(defstruct matrix
rows
columns
(contents (:type list)))
So does using :type eliminate run-time checks? or if it is possible how do you use :type to eliminate run-time checks?
I am working on a linear algebra system in Common Lisp and I would like to make it efficient. So, I am wondering if by doing (like above) (contents (:type list)) if the compiler is going eliminate the run-time check that the compiler would do if contents was not declared as a list.
Thanks