Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lisp cons函数的问题_Lisp - Fatal编程技术网

Lisp cons函数的问题

Lisp cons函数的问题,lisp,Lisp,我最近开始学习lisp,在做一个小程序时发现了一个小问题。 问题是编写一个函数,如果名称还没有标题,则在名称中添加标题。我的代码是: (setf *man-names* '(carlos pablo dani sergio)) (setf *woman-names* '(eva alba luna laura)) (defun titledp (name) (cond ((member (car name) *man-names*) nil) ((member (c

我最近开始学习lisp,在做一个小程序时发现了一个小问题。 问题是编写一个函数,如果名称还没有标题,则在名称中添加标题。我的代码是:

(setf *man-names* '(carlos pablo dani sergio))
(setf *woman-names* '(eva alba luna laura))

(defun titledp (name)
    (cond ((member (car name) *man-names*) nil)
          ((member (car name) *woman-names*) nil)
          (t t)))
(defun add-title (name)
    (cond ((member (car name) *man-names*) (cons 'Mr. name))
          ((member (car name) *woman-names*) (cons 'Mrs. name))))

(defun title (name)
    (cond ((titledp (name)) name)
          (t add-title (name))))
当在“addtitle”中调用cons时,我遇到一个问题,即函数“name”未定义。为什么会这样?我怎样才能修好它


谢谢:)

你的括号很有趣。在
title
函数中,可以多次使用
(名称)
。这意味着调用名为
name
的函数时不带任何参数。我想这就是你想要的:

(defun title (name)
    (cond ((titledp name) name)
          (t (add-title name))))

你的括号很有趣。在
title
函数中,可以多次使用
(名称)
。这意味着调用名为
name
的函数时不带任何参数。我想这就是你想要的:

(defun title (name)
    (cond ((titledp name) name)
          (t (add-title name))))

由于您希望名称值有一个列表,因此需要提交一个列表。
因此,(addtitle'(carlos))或(addtitle(list'carlos))将起作用。

因为您希望您的姓名值有一个列表,所以需要提交一个列表。
因此,(添加标题(carlos))或(添加标题(列表“carlos”)将起作用。

如何称呼它<代码>(添加标题(carlos))返回clisp中的
(carlos先生)
。这是预期的吗?你怎么称呼它<代码>(添加标题(carlos))返回clisp中的
(carlos先生)
。这是预期的吗?谢谢,但我很困惑地认为cons问题在该函数中:(谢谢,但我很困惑地认为cons问题在该函数中:(我不知道该如何感谢你。我正在发疯,以为问题在前一个函数中,但它就在我面前。我不知道该如何感谢你。我正在发疯,以为问题在前一个函数中,但它就在我面前。