作业:子列表?检查某项是否是第一个的子列表 [英] Homework: Sublist? checking if an item is a sublist of the first one

查看:275
本文介绍了作业:子列表?检查某项是否是第一个的子列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个程序需要使用Racket用Scheme编写,它具有以下属性,我很困惑.该函数称为sublist?,具有两个输入SL的两个输入.它检查S是否是L的子列表,并返回#t#f.

So I have this program that needs to be written in Scheme using Racket that has the following properties and I am stumped. The function is called sublist? with two inputs of S and L which are both lists. It checks whether S is a sublist of L and returns #t or #f.

示例将类似于:

sublist? of (A A) and (A B C) is #f
sublist? of (A B C) and (A B D A B C D) is #t
sublist? of (A (B)) and (C ((A (B))) (C)) is #t

需要创建一个名为extractLists的小函数来提取列表,并使用(atomicSublist S L)检查两个提取的列表以查看S的每个元素是否在L中.

A small function called extractLists needs to be created to extract the lists and (atomicSublist S L) is used to check the two extracted lists to see if every element of S is in L.

到目前为止,我已经拥有

So far I have

(define (atomicSublist S L)
  (cond ((null? L) #f)
        ((equal? S (car L)) #t)
        (else (atomicSublist S (cdr L)))))

第二部分并没有真正做任何事情,甚至没有输出S的提取值.

The second part does not really do anything and doesn't even output the extracted value of S.

更新的代码: 为了测试,我使用atomicSublist进行检查.

Updated code: Just for testing I use atomicSublist to check for now.

推荐答案

从一个简单的问题开始,然后进行概括.

Begin with a simpler problem and then generalize.

您将如何编写一个函数来检查符号'a是否为列表?

How would you write a function that checks whether a symbol 'a is an a list or not?

这篇关于作业:子列表?检查某项是否是第一个的子列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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