Post AWTlIRerc8U4mPQs9w by loke@functional.cafe
 (DIR) More posts by loke@functional.cafe
 (DIR) Post #AWTkz7aA20tL0u1CVM by galdor@emacs.ch
       2023-06-08T10:43:03Z
       
       0 likes, 0 repeats
       
       #CommonLisp type declarations are a life saver, but they are fundamentally limited: you cannot use them to express that a list contains elements of a specific types. Frustrating given how ubiquitous lists are. #Erlang type specifications are much more flexible.
       
 (DIR) Post #AWTlIRerc8U4mPQs9w by loke@functional.cafe
       2023-06-08T10:46:32Z
       
       0 likes, 0 repeats
       
       @galdor Type specifications are only advisory, and most CL implementations only use parts of them. They are explicitly not assertions.You may want to look at Coalton for a static CL type system.
       
 (DIR) Post #AWTlmIo55Ugm10ys0e by galdor@emacs.ch
       2023-06-08T10:51:57Z
       
       0 likes, 0 repeats
       
       @loke They are advisory, but major implementations use them to signal type errors. As it should be. I would not use Common Lisp if they were ignored, minimal type checking is a necessity.
       
 (DIR) Post #AWTpjd3Zk4bBldD0q0 by glitzersachen@hachyderm.io
       2023-06-08T11:36:17Z
       
       0 likes, 0 repeats
       
       @galdor what about (or (cons symbol) null)? Probably not expressing what I thought?
       
 (DIR) Post #AWTptDx5w1xAnpkjqK by galdor@emacs.ch
       2023-06-08T11:38:02Z
       
       0 likes, 0 repeats
       
       @glitzersachen What do you expect this form to describe?
       
 (DIR) Post #AWTwO0AJqKSOkJzuRE by glitzersachen@hachyderm.io
       2023-06-08T12:50:49Z
       
       0 likes, 0 repeats
       
       @galdor A list of symbols. SBCL didn't downright reject this, but complained e.g about cons when I assigned a default of nil to the slot, so nil is not a cons, therefore this form. I just tried this yesterday and was too tired to actually try to make sense from various texts on lisp type specifiers, so this might be totally bogus (probably is -- think about that I didn't do much with this slot yet, so I expect it will blow up later. )
       
 (DIR) Post #AWTx9CHaboqnwBu208 by galdor@emacs.ch
       2023-06-08T12:59:22Z
       
       0 likes, 0 repeats
       
       @glitzersachen The CONS type specifier cannot be used to enforce the type of the elements in a list.For example, the (CONS INTEGER) type specification (which is a shortcut for (CONS INTEGER T) will match any cons cell whose car is an integer and whose cdr is anything. So (CONS INTEGER) will match '(1 2 3), but it will also match '(1 "2" 3.14).See http://www.lispworks.com/documentation/HyperSpec/Body/t_cons.htm for more information.
       
 (DIR) Post #AWTxRITQKWzQLo4KDg by glitzersachen@hachyderm.io
       2023-06-08T13:02:37Z
       
       0 likes, 0 repeats
       
       @galdor Ah, damn. Thanks for the clarification. I can still write (or cons null), I suppose and enforce the symbol elements by a suitable accessor and document it with comment, but regardless: I agree, I'd prefer a ML style type system as type assertion language :-(
       
 (DIR) Post #AWTxiV0F02dg8HcaMy by carlozancanaro@aus.social
       2023-06-08T13:05:42Z
       
       0 likes, 0 repeats
       
       @galdor Common Lisp's types are very frustrating. They're too low-level to helpfully model application-level things. I frequently want to do some "type-directed" stuff with classes and/or macros, but the type system makes it hard to do so using standard types.For lists, I hack something together like this:(defun make-sequence-predicate (item-type)  (let ((name (intern (format nil "SEQUENCE-OF-~a" item-type))))    (unless (fboundp name)      (setf (fdefinition name)            (lambda (object)              (every (lambda (item)                       (typep item item-type))                     object))))    name))(deftype list-of (item)  (if (eq item '*)      'list      `(and list (satisfies ,(make-sequence-predicate item)))))
       
 (DIR) Post #AWTy5jkSLJEIWcJpKK by galdor@emacs.ch
       2023-06-08T13:09:56Z
       
       0 likes, 0 repeats
       
       @carlozancanaro Yes I understand the frustration. One has to remember that all type systems are a compromise (see Haskell to understand how insane things can become when you refuse to compromise).
       
 (DIR) Post #AWU5T9gSmR3FIoZ5SS by rwxrwxrwx@mathstodon.xyz
       2023-06-08T14:32:34Z
       
       0 likes, 0 repeats
       
       @galdor What would be the problem with the following?(defun number-list-p (xs)  (and (listp xs) (every #'numberp xs)))(deftype number-list () '(satisfies number-list-p))(typep '(1 a b 2) 'number-list) => NIL(typep '(1 2 3 4) 'number-list) => T
       
 (DIR) Post #AWU7jmFJNJ0fRTv18a by galdor@emacs.ch
       2023-06-08T14:58:00Z
       
       0 likes, 0 repeats
       
       @rwxrwxrwx You need one global function for each type because SATISFIES require a symbol bound to a global function.This is clearly working against the grain.
       
 (DIR) Post #AWU85aQjzBUFARfEem by rwxrwxrwx@mathstodon.xyz
       2023-06-08T15:01:53Z
       
       0 likes, 0 repeats
       
       @galdor I don't think it's a problem but to each their own.