Hi<div><br></div><div>Thank you for the response </div><div><br></div><div>I did not like the compile so I came up with the following:</div><div><br></div><div><div>? (let ((xtype nil))</div><div>(defun mytype (e)</div><div>
(or (null e)<span class="Apple-tab-span" style="white-space:pre"> </span></div><div> (and (consp e)</div><div> (typep (car e) `,xtype)</div><div> (mytype (cdr<span class="Apple-tab-span" style="white-space:pre"> </span>e)))))</div>
<div>(deftype list-of (type)</div><div> (setf xtype type)</div><div> '(satisfies mytype)))</div><div>LIST-OF</div><div>? (typep '(2 3) '(list-of integer))</div><div>T</div><div>? (typep '(x y) '(list-of symbol))</div>
<div>T</div><div>? (typep '(x 3) '(list-of symbol))</div><div>NIL</div><div>?</div><div><br></div><div>Kind regards</div><div>Taoufik</div><br><div class="gmail_quote">On Thu, Jul 26, 2012 at 7:56 PM, Pascal J. Bourguignon <span dir="ltr"><<a href="mailto:pjb@informatimago.com" target="_blank">pjb@informatimago.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Taoufik Dachraoui <<a href="mailto:dachraoui.taoufik@gmail.com">dachraoui.taoufik@gmail.com</a>> writes:<br>
<br>
> Hi<br>
><br>
> I would like to define a recursive type as follows:<br>
><br>
> (deftype list-of (type)<br>
> `(or null (cons ,type (list-of ,type))))<br>
><br>
> This does not work (stack overflow)<br>
><br>
> How can define such types?<br>
<br>
<br>
</div>cl-user> (deftype list-of (type)<br>
(let ((funame (gensym (prin1-to-string `(list-of ,type)))))<br>
(compile funame `(lambda (x)<br>
(declare (ftype (function (t) t) ,funame))<br>
(or (null x)<br>
(and (consp x)<br>
(typep (car x) ',type)<br>
(,funame (cdr x))))))<br>
`(satisfies ,funame)))<br>
<br>
list-of<br>
cl-user> (typep '("one" "two" "three") '(list-of string))<br>
t<br>
cl-user> (typep '("one" 3 "three") '(list-of string))<br>
nil<br>
cl-user><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
__Pascal Bourguignon__ <a href="http://www.informatimago.com/" target="_blank">http://www.informatimago.com/</a><br>
A bad day in () is better than a good day in {}.<br>
<br>
_______________________________________________<br>
Openmcl-devel mailing list<br>
<a href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a><br>
<a href="http://clozure.com/mailman/listinfo/openmcl-devel" target="_blank">http://clozure.com/mailman/listinfo/openmcl-devel</a><br>
</font></span></blockquote></div><br></div>