Lisp:CHAR既不声明也不绑定 [英] Lisp: CHAR is neither declared nor bound

查看:209
本文介绍了Lisp:CHAR既不声明也不绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经决定在几天之前学习(普通)Lisp,而且我意识到这是一个很新鲜的问题,对于至少有一点经验的人来说,这可能是非常微不足道的。


所以基本上发生的是我加载Emacs + Slime(通过Lisp in a Box)并写我的程序(包含在下面):

 (defun last-char(s)获取最后一个字符
(char s( - (length s)1)))

然后我尝试使用 C - c M-k 得到以下警告:


CHAR既不声明也不绑定,
将被视为已被声明为SPECIAL。 / p>

此警告的含义是什么?我想这可能是类似于忘记#包含在C中的东西,但我不太清楚。我该怎么办?我只是忽略它?

解决方案

警告意味着 char 不被认为是一个功能,因为它应该是由于某些原因(它的报告,该符号是未绑定,它没有价值)。



它可能与您的实现有关。我在SBCL + Emacs / Slime(和Clozure)中使用Cc Mk运行代码,并从SBCL的汇编中获得以下报告:

 ;在:DEFUN LAST-CHAR 
; (CHAR S( - (LENGTH S)1))
; - > AREF
; ==>
; (SB-KERNEL:HAIRY-DATA-VECTOR-REF ARRAY SB-INT:INDEX)
;
;注意:无法
;优化
;由于类型不确定性:
;第一个参数是STRING,而不是SIMPLE-STRING。
;
;注意:无法
;避免运行时调度数组元素类型
;由于类型不确定性:
;第一个参数是STRING,而不是SIMPLE-ARRAY。

尝试只输入

在REPL上的#'char 

,响应应该是报告作为一个功能,

  CL-USER> #'char 
#< FUNCTION CHAR>

但也许它不在你的实现中(我猜这不是,给定编译器警告和代码在SBCL中正确编译的事实)。如果是这样,那么这就是您的实现离开ANSI Common Lisp规范的一个点,因为该功能应该在那里。


I have decided to learn (Common) Lisp a few days ago and I realize that this is quite a newbie question and it is probably extremely trivial to someone with at least a bit of experience.

So basically what happens is that I load up Emacs + Slime (via Lisp in a Box) and write my program (included below):

(defun last-char (s) "Get last character"
       (char s (- (length s) 1)))

And then I try to compile it with C - c M - k, but then I get the following warning:

CHAR is neither declared nor bound, it will be treated as if it were declared SPECIAL.

What is the meaning of this warning? I suppose it might be something similar to forgetting #includes in C, but I can't quite figure it out. What should I do about it? Shall I just simply ignore it?

解决方案

The warning means that char is not being recognized as a function, as it should, for some reason (it's reporting that the symbol is unbound, it has no value).

It might have something to do with your implementation. I've run your code using C-c M-k in my SBCL + Emacs/Slime (and in Clozure) and I get the following report from the compilation in SBCL:

; in: DEFUN LAST-CHAR
;     (CHAR S (- (LENGTH S) 1))
; --> AREF 
; ==>
;   (SB-KERNEL:HAIRY-DATA-VECTOR-REF ARRAY SB-INT:INDEX)
; 
; note: unable to
;   optimize
; due to type uncertainty:
;   The first argument is a STRING, not a SIMPLE-STRING.
; 
; note: unable to
;   avoid runtime dispatch on array element type
; due to type uncertainty:
;   The first argument is a STRING, not a SIMPLE-ARRAY.

Try just typing

#'char 

on the REPL, the response should be that it is reported to be a function,

CL-USER> #'char
#<FUNCTION CHAR>

but maybe it doesn't in your implementation (I'm guessing it doesn't, given the compiler warning and the fact that the code compiles correctly in SBCL). If that's the case, then that is a point where your implementation departs from the ANSI Common Lisp specification, because that function should be there.

这篇关于Lisp:CHAR既不声明也不绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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