4 ms·
I understand that, internally, everything is of some type. What Lisp is lacking though is type declarations for variables, method parameters and returned value
by lgieron 12y ago
I 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?