Common-Lisp递归类型说明符 [英] Common-Lisp Recursive Type Specifier

查看:73
本文介绍了Common-Lisp递归类型说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我想为列表编写一个类型说明符,以允许指定列表元素的类型。像这样的东西:

So I would like to write a type specifier for list that allows one to specify the types of the list elements. Something like :

(deftype list-of (v) (cons ,v (or null (list-of ,v))))

但是,这当然行不通,因为众所周知,递归类型不是支持的。当然,可以映射类似满足的内容(如此处所述:是否可以在Common Lisp中定义递归类型?),但是这种否定了适用于语言分析和脱机代码分析的干净递归定义的优势。 (例如,证明代码正确,或在各种语言之间进行翻译)。

but of course, that's not going to work because as we all know, recursive types are not supported. One could map something like "satisfies" of course (as has been mentioned here: Is it possible to define a recursive type in Common Lisp?), but that kind of negates the advantage of a clean recursive definition suitable for language analysis and offline code analysis. (E.g., proving code is correct, and or translating between languages).

有什么建议吗?似乎这是标准的缺失,除非我缺少明显的东西,考虑到我们通常使用列表来表示集合-为什么没有一种简单的方法来声明set元素的类型?

Any suggestions? Seems like this is a missing bit of standard, unless I'm missing something obvious, given we typically use lists to represent sets - why not have a simple way to declare the types of set elements?

推荐答案

对不起,这是不允许的。 DEFTYPE 规范说:

Sorry, this isn't allowed. The DEFTYPE specification says:


由于必须终止扩展而返回的类型说明符的递归扩展,包括嵌套在扩展中的类型说明符的扩展。 p>

Recursive expansion of the type specifier returned as the expansion must terminate, including the expansion of type specifiers which are nested within the expansion.

此语言是 RECURSIVE-DEFTYPE 标准化过程中的清理问题。一个实现可以在某些情况下允许递归类型定义作为扩展,但是您不能移植它。

This language was the result of a the RECURSIVE-DEFTYPE cleanup issue during the standardization process. An implementation could allow recursive type definitions in some cases as an extension, but you can't depend on it portably.

这篇关于Common-Lisp递归类型说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆