LISP:删除列表中某个特定变量的所有事件

LISP:删除列表中某个特定变量的所有事件,lisp,clisp,Lisp,Clisp,我必须编写一个函数,从中我可以删除列表中某个特定变量的所有事件 我正在Ubuntu文本编辑器中编程 我的Lisp代码如下所示: #! /usr/bin/clisp (defun my-remove(lst var1) (cond ((eq lst nil) nil) ((eq (car (cdr lst)) var1)(cons (car lst) (my-remove (cdr(cdr lst)) var1))) ( t (my-remove (cdr lst

我必须编写一个函数,从中我可以删除列表中某个特定变量的所有事件
我正在Ubuntu文本编辑器中编程
我的Lisp代码如下所示:

   #! /usr/bin/clisp


(defun my-remove(lst var1)
  (cond
   ((eq lst nil) nil)
   ((eq (car (cdr lst)) var1)(cons (car lst) (my-remove (cdr(cdr lst)) var1)))
    ( t (my-remove (cdr lst) var1))
  )
)

问题是它没有从列表中删除任何元素

您需要查看列表中的第一个元素<代码>(car(cdr lst))不是列表中的第一个元素

如果该元素与要删除的元素相等,则要跳过该元素并继续向下列表。如果它们不相等,则希望将该元素包括在继续向下列表得到的结果中

在这两种情况下,“继续列表”-位应该是相同的,变化取决于是否包含您正在查看的元素

此外,您可能希望使用
eql
equal
而不是
eq
来比较元素
eql
是传统的默认比较器


这看起来像是家庭作业,所以我不会直接给你代码,但希望这能帮助你朝着正确的方向前进。

你需要查看列表中的第一个元素<代码>(car(cdr lst))不是列表中的第一个元素

如果该元素与要删除的元素相等,则要跳过该元素并继续向下列表。如果它们不相等,则希望将该元素包括在继续向下列表得到的结果中

在这两种情况下,“继续列表”-位应该是相同的,变化取决于是否包含您正在查看的元素

此外,您可能希望使用
eql
equal
而不是
eq
来比较元素
eql
是传统的默认比较器

这看起来像是家庭作业,所以我不会直接给你代码,但希望这能帮助你朝着正确的方向前进。

你想做什么:

if you have an empty list, return the empty list and do no more
if the very first element of the list has the value to be purged:
  return the result of calling the "purge this value" on the rest of the list
otherwise:
  create a new list with:
    the head of the list
    the result of purging the value from the rest of the list
你在做什么:

if there's an empty list, return the empty list and do no more
if the second element is the value to purge:
  create a new list consisting of:
    the head of the list
    the result of purging the value from the rest of the rest of the list
otherwise:
  return the result of purging the value from the rest of the list
你想做什么:

if you have an empty list, return the empty list and do no more
if the very first element of the list has the value to be purged:
  return the result of calling the "purge this value" on the rest of the list
otherwise:
  create a new list with:
    the head of the list
    the result of purging the value from the rest of the list
你在做什么:

if there's an empty list, return the empty list and do no more
if the second element is the value to purge:
  create a new list consisting of:
    the head of the list
    the result of purging the value from the rest of the rest of the list
otherwise:
  return the result of purging the value from the rest of the list

我已经尝试了很多,但仍然无法理解……如果你能帮助我编写代码……我可以对其进行反向工程并理解它我已经尝试了很多,但仍然无法理解它……如果你能帮助我编写代码……我可以对其进行反向工程并理解它