计划作业
如何设计一个功能内容 输入一个原子列表 lat 并返回 lat 的内容。因此 '(abcabcdd) 的内容是 '(abcd)。
how to design a function content which
inputs a single list of atoms lat and which returns
the content of lat.Thus the content of '(a b c a b c d d) is '(a b c d).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
下面的过程
content
应该可以满足您的需要。过程
content
接受一个列表作为参数。它将列表发送到另一个名为work
的过程。此过程处理列表并将列表中的项目添加到新列表中(如果它们尚不在新列表中)。work
过程使用了另一个名为in
的过程,该过程检查某个项目是否是列表的成员。我的解决方案本质上将您的问题分为两个子问题,并使用比原始问题抽象级别更低的过程。
希望有帮助。
The procedure
content
below should get you what you need.The procedure
content
accepts a list as a parameter. It sends the list to another procedure calledwork
. This procedure processes the list and adds the items in the list to a new list (if they are not already in the new list). Thework
procedure makes use of yet another procedure calledin
, which checks to see if an item is a member of a list.My solution essentially divides your problem into two sub-problems and makes use of procedures which operate at a lower level of abstraction than your original problem.
Hope that helps.
这是PLT方案解决方案:
检查一下:
It is PLT Scheme solution:
Check it:
小阴谋家风格怎么样,
How about little schemer style,
从简单地创建传入列表的副本的过程开始(非常容易做到):
为了确保输出列表的元素是唯一的,如果 REST 的头已经是 ANS 的成员,我们应该跳过 CONS。因此我们添加另一个条件来做到这一点:
Start from a procedure that simply creates a copy of the passed-in list (very easy to do):
To ensure that the output list's elements are unique, we should skip the CONS if the head of REST is already a member of ANS. So we add another condition to do just that:
以下函数接受一个列表并使用递归返回一个新列表,其中仅包含其参数的唯一输入:
正如评论中提到的,common lisp 已经具有此函数:
The following function takes in a list and returns a new list with only the unique inputs of it's argument using recursion:
As was mentioned in the comments, common lisp already has this function: