1 answer

You must write each of the following scheme functions. You must use only basic scheme functions...

Question:

You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects.

This problem need to use DrRacket software. Racket Language.

Write a function named (first-n L1 N) that returns the first N elements of L1. If N is negative, return the empty list. If N exceeds the length of L1 return all elements of L1.

(first-n '(a b c d e f) 3) ---> (a b c) (first-n '(a b c d e f) -3) ---> () (first-n '(a b c d e f) 33) ---> (a b c d e f) (first-n '() 0) ---> ()

Answers

Code:

(define count 1) ;;Initialized count = 1 to keep track our traversal of list

(define (first-n L1 N) ;;MAIN_FUNCTION
(first L1 N count)) ;;calls sub-function Which returns first N-number of elements of list


(define (first L1 N count) ;;SUB_FUNCTION
(cond ((null? L1) L1) ;;if list is empty returns List
((< N 0) '()) ;;if (N < 0) RETURNS NULL LIST
((= N 0) '()) ;;if (N == 0) reurns NULL list
((= N 1) (car L1)) ;;if (N == 1) Returns 1st element
((= N count) (cons (car L1) '())) ;;if (N == count) returns list which contains elelemnt at index N

(else (cons (car L1) (first (cdr L1) N (+ 1 count)))))) ;;else construct list with first element and continue

Snapshot of Code and Output:

File Edit View Language Racket Insert Scripts Tabs Help Untitled (define...) #lang scheme (define count 1) ;; Initialized cou

.

Similar Solved Questions

1 answer
A synthetic European put option is created by: Buying the discount bond, buying the call option,...
A synthetic European put option is created by: Buying the discount bond, buying the call option, and short-selling the stock. Buying the call option, short-selling the discount bond, and short-selling the stock. Short-selling the stock, buying the discount bond, and selling the call option....
1 answer
HW03 - 1 to 4 Problem 1 Find a regular expression for the set ^a"bm: (n...
HW03 - 1 to 4 Problem 1 Find a regular expression for the set ^a"bm: (n + m) is odd Problem 2 Give regular expressions for the following languages. 3. The complement of L 4. The complement of L2 Problem 3 Find a regular expression for L = {w: na(w) and nb(w) are both even } Problem 4 Find dfa&#...
1 answer
4. A company manufactures two products, X and Y by using three machines A, B, and...
4. A company manufactures two products, X and Y by using three machines A, B, and c Each of the products has to be processed on each machines. The Table below shows (a) the hours required on each machine to produce one unit of each of the products (b) the total number of hours available on each mach...
1 answer
Non-volatile acids  Are produced by _____________ reactions  Non-volatile acids do not _________ easily. ...
Non-volatile acids  Are produced by _____________ reactions  Non-volatile acids do not _________ easily.  These acids are excreted by the ________only.  Examples of non-volatile acids include _______ ______ ______...
1 answer
PLEASE HELP, WILL GIVE THUMBS UP ON ALL MY ACCOUNTS, PLEASE FOLLOW CAREFULLY This practice will...
PLEASE HELP, WILL GIVE THUMBS UP ON ALL MY ACCOUNTS, PLEASE FOLLOW CAREFULLY This practice will aid you in creating an ERD diagram. Explaining the entities the relationships and all the cardinalities that your business holds. Write up a database application to solve a business problem. This is to de...
1 answer
What are the two key things that an advertising pre-test measures: a. Persuasiveness and ad break-through...
What are the two key things that an advertising pre-test measures: a. Persuasiveness and ad break-through b. Brand recall and persuasiveness c. Persuasiveness and brand equity d. Brand recall and reason to believe e.   None of these...
1 answer
What is the early childhood educators role on providing nutrition education for young children
What is the early childhood educators role on providing nutrition education for young children...
1 answer
Evidence-based medicine might be defined as the appropriate application of the best available evidence to determine...
Evidence-based medicine might be defined as the appropriate application of the best available evidence to determine diagnosis and treatment for patients. Should the controlled terminology used in knowledge representation be evidence based? What would that evidence be like?...
1 answer
Find the arc length of the function below?
#y=\ln(\secx)#, with parameters #0\lex\le\pi/4#?...
1 answer
This is just your basic understanding about the micro economics. In this essay you will explain....
This is just your basic understanding about the micro economics. In this essay you will explain. how advertisement has impact on their consumer behavior.?...
1 answer
There are many different types of hot dogs produced in the U.S. The data to the...
There are many different types of hot dogs produced in the U.S. The data to the right represents the published mean calorie contents of the various brands that produce beef hot dogs and the mean calorie contents of various brands that produce poultry hot dogs. (Treat these as samples.) Compute the m...
1 answer
A researcher is interested in seeing if different study techniques can influence test scores. An experiment was designed in which students are randomly assigned to one of three groups based on how the...
A researcher is interested in seeing if different study techniques can influence test scores. An experiment was designed in which students are randomly assigned to one of three groups based on how they study for a quiz. Group 1 simply reads the chapter, Group 2 reads and takes notes, Group 3 reads, ...
1 answer
12. Calculate the energy released, in kJ, when 1.00 mol U-238 isotopes (nuclear mass = 238.05078...
12. Calculate the energy released, in kJ, when 1.00 mol U-238 isotopes (nuclear mass = 238.05078 amu) decays via a particle emission to form thorium-234 (nuclear mass = 234.03596 amu). The nuclear mass of helium-4 is 4.002603 amu. The speed of light = 2.997925x108 m/s and 1 amu = 1.660538x10-24 g...
1 answer
A cylinder contains 12.6 L of air at a total pressure of 41.4 psi and a...
A cylinder contains 12.6 L of air at a total pressure of 41.4 psi and a temperature of 25C Part A How many moles of gas does the cylinder contain? (Hint: You must convert each quantity into the correct units (L. atm. mol. and K) before substituting into the ideal gas law.) Express your answer with t...
1 answer
In a current operation a 5 HP 120 VAC capacitor start motor is used to run...
In a current operation a 5 HP 120 VAC capacitor start motor is used to run a pump. The pump and motor are scheduled to be replaced. Options for the replacement are: 1) use the same model pump and motor, 2) a 240 VAC single phase capacitor start motor and matching pump, and 3) a 240 VAC three phase m...
1 answer
If a current of #8 A# passing through a circuit generates #72 W# of power, what is the resistance of the circuit?
If a current of #8 A# passing through a circuit generates #72 W# of power, what is the resistance of the circuit?...
1 answer
Problem 2 (25%): • Write an HTML file to prompt to the visitor to input the...
Problem 2 (25%): • Write an HTML file to prompt to the visitor to input the user's weight in kilograms and height in meters, and then display the result of the user's Body Mass Index (BMI) (15%) • Please write a function to calculate the BMI result (10%) o Formula: BMI=weight (kg) ...