3 ms·
Not sure if I've understood the question about types in CL. * (type-of 1) BIT * (type-of 123) (INTEGER 0 4611686018427387903) * (type-of "hi") (
by dschiptsov 12y ago
Not sure if I've understood the question about types in CL.
* (type-of 1)
BIT
* (type-of 123)
(INTEGER 0 4611686018427387903)
* (type-of "hi")
(SIMPLE-ARRAY CHARACTER (2))
* (type-of 'hi)
SYMBOL
*
And there is also typecase macro which is basically cond on type-of - the way to do dispatch on a type.
This technique of extending a language with new special forms using macros is the essence of Lisps.
- lgieron 12y agoI understand that, internally, everything is of some type. What Lisp is lacking though is type declarations for variables, method parameters and returned values. These make codebases immensely more readable.
- lispm 12y agoCommon Lisp added type declarations in 1984. A usual type declaration looks like this: (defun month-name (month) (declare (type (integer 1 12) month)) (the string (ecase month (1 "Jan") (2 "Feb") (3 "Mar") (4 "Apr") (5 "May") (6 "Jun") (7 "Jul") (8 "Aug") (9 "Sep") (10 "Oct") (11 "Nov") (12 "Dez")))) You can also declare the type of the function, outside of the function: (declaim (ftype (function ((integer 1 12)) ; the parameter list string) ; the return value month-name)) ; the function name CLOS (the Common Lisp Object System) was added a few years later. CL-USER 1 > (defmethod add ((a integer) (s string)) (+ a (parse-integer s))) #<STANDARD-METHOD ADD NIL (INTEGER STRING) 402005B1C3> CL-USER 2 > (add 12 "23") 35 What do you think the words 'integer' and 'string" are about?