在普通的Lisp中,我该如何以可移植的方式检查对象的类型 [英] In common lisp, how can I check the type of an object in a portable way

查看:59
本文介绍了在普通的Lisp中,我该如何以可移植的方式检查对象的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义一个专门处理带有无符号字节8个元素的数组类型对象的方法.在sbcl中,当您(make-array x :element-type '(unsigned-byte 8))时,对象类由SB-KERNEL :: SIMPLE-ARRAY-UNSIGNED-BYTE-8实现.有没有专门针对无符号字节数组类型的与实现无关的方法?

I want to define a method that will specialize on an object of array type with unsigned byte 8 elements. In sbcl, when you (make-array x :element-type '(unsigned-byte 8)) the object class is implemented by SB-KERNEL::SIMPLE-ARRAY-UNSIGNED-BYTE-8. Is there an implementation independent way of specializing on unsigned-byte array types?

推荐答案

使用尖锐的点在读取时插入依赖于实现的对象类:

(defmethod foo ((v #.(class-of (make-array 0 :element-type '(unsigned-byte 8)))))
  :unsigned-byte-8-array)

sharpsign -dot reader宏在读取时评估表单,确定数组的类.该方法将专门用于特定Common Lisp实现用于数组的类.

The sharpsign-dot reader macro evaluates the form at read-time, determining the class of the array. The method will be specialized on the class the particular Common Lisp implementation uses for the array.

这篇关于在普通的Lisp中,我该如何以可移植的方式检查对象的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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