I would like to define a type for a list of elements of a given type. For
the sake of simplicity lets assume that the element type is fixnum and
defined as:
(deftype d3-antwort () 'fixnum)
Intuitively I tried (deftype d3-antworten () '(list d3-antwort)),
to declare a list of d3-antwort but this does not work.
I came up with using (and list (satisfies predicate)) as in the following
code, but this looks like a crutch.
Is there a more elegant way to do this?
Karsten
(defun d3-listen-antwortp (list)
(every #'(lambda(was)
(typep was 'd3-antwort))
list))
(deftype d3-antworten () '(and list (satisfies d3-listen-antwortp)))
From: Barry Margolin
Subject: Re: Declare the type of the elements in a list?
Date:
Message-ID: <3h05lm$ot2@tools.near.net>
In article <··········@rheged.dircon.co.uk> ·····@rheged.dircon.co.uk (Simon Brooke) writes:
>The type of all elements in all lists in all LisPs is a given type,
>to whit CONS-CELL.
That's not true. The elements of a list are the objects referred to by the
cars of the cons cells that constitute the list. From CLtL2, p.30: "The
<car> components of the conses are called the <elements> of the list."
Also, the description of NTH says that it returns the nth element of the
list, but it doesn't return the cons cell (that's what NTHCDR does).
E.g., the elements of the list (A 1 "foo" (B)) are the symbol A, the fixnum
1, the string "foo", and the list (B). Three out of four of those are not
of type CONS (there is no CL type named CONS-CELL).
--
Barry Margolin
BBN Internet Services Corp.
······@near.net
In article <··········@peaches.cs.utexas.edu> ·······@cs.utexas.edu (David Gadbois) writes:
Karsten Poeck asks if there is any way to parameterize the LIST type
so as to specify the types of a list's elements. The answer is no;
the LIST type specifier does not take any subsidiary type information.
It would be nice if it did, but those are the breaks. You have to go
the SATISFIES route.
I believe that ANSI Common Lisp specifies that the CONS type specifier
can indeed take a subsidiary type specifier as an argument, but such
argument only specifies the type of the CAR (e.g., the first element
of a list, but not necessarily all elements).
--
Lawrence G. Mayka
AT&T Bell Laboratories
···@ieain.att.com
Standard disclaimer.