Question

In: Computer Science

Please use the Scheme programming language with Dr. Racket to solve a and b below. (Use...

Please use the Scheme programming language with Dr. Racket to solve a and b below. (Use Scheme and not Python)

Write before–in–list?, which takes a list and two elements of the list. It should return #t if the second argument appears in the list argument before the third argument:

> (before–in–list? '(back in the ussr) 'in 'ussr)
#T
> (before–in–list? '(back in the ussr) 'the 'back)
#F

The procedure should also return #f if either of the supposed elements doesn't appear at all.

Solutions

Expert Solution

Code:

(define (before-in-last? list x y)
(cond
((null? list) #f) ;; if list empty returns false
((equal? (car list) x) (member? y (cdr list))) ;;if second arg = 1st element of list, check for third arg in rest of the list
((equal? (car list) y) #f) ;;if third argument is 1st element of the list return true as it has to appear after second argument
(else (before-in-last? (cdr list) x y)))) ;;otherwise recursively traverse rest of the list


(define (member? a list) ;;checks an element is member of list or not
(cond ((null? list ) #f) ;;if list is empty returns false
((equal? (car list)a) #t) ;;if searching element is equal to first member of list returns true
(else (member? a (cdr list))))) ;;otherwise check in remaining list

Snapshot of Code and Output:


Related Solutions

How to create a divide function in (Dr Racket) programming language without using the built in...
How to create a divide function in (Dr Racket) programming language without using the built in function " / " ?
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that...
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define...
*****************PLEASE PROVIDE THE CODE IN RACKET PROGRAMMING LANGUAGE ONLY AND MAKE SURE CODE RUNS ON THE...
*****************PLEASE PROVIDE THE CODE IN RACKET PROGRAMMING LANGUAGE ONLY AND MAKE SURE CODE RUNS ON THE WESCHEME IDE************* Write a tail-recursive Racket function "kept-short-rec" that takes an integer and a list of strings as parameters and evaluates to an integer. The resulting integer should be the number of strings on the original list whose string length is less than the integer parameter. For example, (kept-short-rec 3 '("abc" "ab" "a")) should evaluate to 2 because there are only 2 strings shorter...
Scheme Programming - Racket R5RS Longest Non-Decreasing Subsequence You will write two Scheme functions that compute...
Scheme Programming - Racket R5RS Longest Non-Decreasing Subsequence You will write two Scheme functions that compute a longest non-decreasing subsequence from a list of numbers. For example, if you type > (lis '(1 2 3 2 4 1 2)) you might get (1 2 3 4) Note that there may be more than one longest non-decreasing subsequence. In the above example, your program might also find (1 2 2 4) or (1 2 2 2). You should concentrate first on...
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the...
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the Weightlifting Walrus is training for a contest where it will have to lift 1000 kg. Wallace has some weight plates lying around, possibly of different weights, and its goal is to add some of the plates to a bar so that it can train with a weight as close as possible to 1000 kg. In case there exist two such numbers which are equally...
This problem should be solved using the DrRacket software in the Racket/Scheme language. Consider two techniques...
This problem should be solved using the DrRacket software in the Racket/Scheme language. Consider two techniques for representing a graph as Scheme lists. We can represent a directed graph as a list of edges. We call this representation an el-graph (i.e. edge-list graph). An edge is itself a list of length two such that the first element is a symbol denoting the source of the edge and the second element is a symbol denoting the target of the edge. Note...
Scheme is a dialect of a programming language called Lisp, which was developed at MIT in...
Scheme is a dialect of a programming language called Lisp, which was developed at MIT in 1959. Alice 1.0 was released in 2006 from CMU, and Python in 1994. Based on what you know of the Scheme language, describe the major differences between how it works and how Alice or Python works. What advantages might Scheme have over Alice/Python? What advantages might Alice/Python have over Scheme?
This problem should be solved using the DrRacket software in Racket/Scheme language. Write a function (merge-sorter...
This problem should be solved using the DrRacket software in Racket/Scheme language. Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the lists to obtain the result. See the following examples for clarificaton. (merge-sorter '(3 1 5 4 2) ---> (1 2 3 4 5)...
Please use the Java Programming language. This is the introductory course, chapter two. Please only use...
Please use the Java Programming language. This is the introductory course, chapter two. Please only use if/else if, else and while loop. We have not touch base with do and while do(I don't know if while do exist in Java). Create an application that converts number grades to letter grades. Console Welcome to the Letter Grade Converter Enter numerical grade: 90 Letter grade: A Continue? (y/n): y Enter numerical grade: 88 Letter grade: A Continue? (y/n): y Enter numerical grade:...
Please use C programming to write the code to solve the following problem. Also, please use...
Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT