剪辑:变量没有值 [英] clisp: variable has no value

查看:85
本文介绍了剪辑:变量没有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让用户程序提取列表中成对的具有元素b(由参数给定)的元素a.

就像,如果我给c作为参数并列出((c a) (c b) (d f) (d g)), 结果应该是'a' 'b';

所以我定义如下函数,

(defun myr (b a) (if (= CAAR(a) b) CDAR(a) 'nope myr(b CDR(a))));

并像这样打电话

myr(b ((b a) (b c) (a d) (a f)))

但是结果就像variable myr has no value

这是我第一次来Lisp,所以只要告诉我应该搜索哪个关键字将对我有很大帮助.

感谢您的阅读.

解决方案

真的需要从一本不错的Lisp书开始,例如 ACL . 您将节省很多时间.

Lisp语法与C不同. 在C语言中,您可以像下面这样调用带有参数хy的函数f:f(x,y). 在Lisp中,您可以这样操作:(f x y).

调用函数myr(...)时,将符号myr放在变量位置,而不是 function 位置,这会导致您报告错误. /p>

您还需要适当地使用 quote .

I want to make user-program which extract elements a which have element b (given by parameter) as pair in list.

Like, if I give c as parameter and list ((c a) (c b) (d f) (d g)), result should be 'a' 'b';

So I define a function as below,

(defun myr (b a) (if (= CAAR(a) b) CDAR(a) 'nope myr(b CDR(a))));

and call like this

myr(b ((b a) (b c) (a d) (a f)))

But result is like variable myr has no value

Its my first time in Lisp, So just tell me what keyword should I search for will be great help for me.

Thank you for reading.

解决方案

You really need to start with a good lisp book, e.g., PCL or ACL. You will save yourself a lot of time.

Lisp syntax is different from C. In C, you call a function f with arguments х and y like this: f(x,y). In Lisp, you do it like this: (f x y).

When you invoke your function myr(...), you put the symbol myr in the variable position, not function position, which causes the error you reported.

You also need to use quote as appropriate.

这篇关于剪辑:变量没有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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