[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gcl-devel] list types
From: |
Pascal Bourguignon |
Subject: |
Re: [Gcl-devel] list types |
Date: |
Tue, 28 Jun 2005 15:59:27 +0200 |
Camm Maguire writes:
> Greetings! Is there a type specifier which restricts elements of a
> list, e.g. '(list symbol)?
Not in Common Lisp.
But in Common Lisp, you can write such a type specifier:
[41]> (typep '(1 2 3) '(restricted-list fixnum))
T
[42]> (typep '(1 2 3) '(restricted-list (integer 1 2)))
NIL
[43]> (typep '(1 2 3) '(restricted-list (integer 1 5)))
T
The only difficulty is that SATISFIES expects a symbol and nothing
else. So we will have to create such symbols on the fly. May be it
could be possible to only use GENSYM's or uninterned symbols, but I
don't think the specification says it should work always, so to be on
the safe side, we'll intern the predicate symbols in a special
package:
(defpackage "$$RESTRICTED-LIST-PREDICATES$$" (:USE))
(defun find-restricted-list-predicate (element-type)
(let* ((name (with-standard-io-syntax (format nil "~S-P" element-type)))
(predicate (FIND-SYMBOL name "$$RESTRICTED-LIST-PREDICATES$$")))
(unless predicate
(setf predicate (intern name "$$RESTRICTED-LIST-PREDICATES$$"))
(eval `(defun ,predicate (list)
(every (lambda (item) (typep item ',element-type)) list))))
predicate))
(deftype restricted-list (element-type)
`(or null
(and cons
(satisfies ,(find-restricted-list-predicate element-type)))))
--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot. don't bother saving your artefacts.
- [Gcl-devel] Version_2_7_0t1, Camm Maguire, 2005/06/22
- Message not available
- Re: [Gcl-devel] Version_2_7_0t1, Camm Maguire, 2005/06/22
- Re: [Gcl-devel] Version_2_7_0t1, Paul F. Dietz, 2005/06/26
- Re: [Gcl-devel] Version_2_7_0t1, Camm Maguire, 2005/06/27
- [Gcl-devel] list types, Camm Maguire, 2005/06/27
- [Gcl-devel] Re: list types, Paul F. Dietz, 2005/06/27
- Re: [Gcl-devel] Re: list types, Camm Maguire, 2005/06/28
- Re: [Gcl-devel] Re: list types, Paul F. Dietz, 2005/06/28
- Re: [Gcl-devel] list types,
Pascal Bourguignon <=
- Re: [Gcl-devel] list types, Paul F. Dietz, 2005/06/28