Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
In Ocaml Write a function l3_of_3l : ’a list * ’b list * ’c list -> (’a * ’b * ’c) list = that transforms a triple of lists into lists of triples. If lengths don’t match then ignore leftover elements.
examples
l3_of_3l ([1;2;3] ,[1.;2.] ,[ ’ a ’; ’b ’; ’c ’; ’d ’]) ;;
- : ( int * float * char ) list = [(1 , 1. , ’a ’) ; (2 , 2. ,’b ’) ]
l3_of_3l ([1.;2.] ,[ ’ a ’; ’b ’; ’c ’; ’d ’] ,[1;2;3]) ;;
- : ( float * char * int ) list = [(1. , ’a ’ , 1) ; (2. , ’b’ , 2) ]
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a function sum_alt that takes a list of numbers zand calculates their alternating sum, defined as n-1 Σ(-1)+1 zk. k=0 Here Zo, Z1, Zn-1 denote the individual elements of the list.arrow_forwardWrite a user defined function named as “length_list” function that finds the length of a list of list_node_t nodes. This code should fit with the following code.Partial Code: #include <stdio.h> #include <stdlib.h> /* gives access to malloc */ #define SENT -1 typedef struct list_node_s { int digit; struct list_node_s *restp; } list_node_t; list_node_t *get_list(void); int main(void) { list_node_t *x;int y; x=get_list(); printf("%d\n",x->digit); printf("%d\n",x->restp->digit); printf("%d\n",x->restp->restp->digit); // your length_list function should be called from here printf("Length is: %d",y); } /* * Forms a linked list of an input list of integers * terminated by SENT */ list_node_t * get_list(void) { int data; list_node_t *ansp; [20]scanf("%d", &data); if (data == SENT) { ansp = NULL; } else { ansp = (list_node_t *)malloc(sizeof (list_node_t)); ansp->digit = data; ansp->restp = get_list(); } return (ansp);arrow_forwardIn Ocaml Map functions left Write a function map_fun_left : (’a -> ’a) list -> ’a list -> ’a list = that is given a list of functions and a list of elements. For each element apply all functions from left to it and keep the result. Return the results as a list. examplesmap_fun_left [((+) 1) ;( * ) 2; fun x - >x -10] [1;2;3;4];;- : int list = [ -6; -4; -2; 0]map_fun_left [( fun x - > int_of_char x | > (+) 32 | >char_of_int ) ;( fun x - > char_of_int (( int_of_char x )+1) ) ] [ ’A ’; ’B ’; ’C ’; ’D ’];;- : char list = [ ’b ’; ’c ’; ’d ’; ’e ’]arrow_forward
- Suppose a node of a doubly linked list is defined as follows: struct Node{ int data; struct Node* next; struct Node* prev; }; Write the function definition of the function deleteElement as presented below. This function deletes a node at position n from a doubly linked list. struct Node* deleteElement(struct Node* head, int n){ //write the function definition }arrow_forwardlst1= [4,3,2,6,2] and lst2=[1,2,4] then the new_list is [2,2,4]. Assign the new-list to variable new_list and sort. Code: What is wrong with this code? lst1= [4,3,2,6,2] lst2=[1,2,4] new_list=[] for elements1 in lst1: for elements2 in lst2: elements1==elements2: new_list.append(elements1) new_list.sort()arrow_forwardWrite a function called find_duplicates which accepts one list as a parameter. This function needs to sort through the list passed to it and find values that are duplicated in the list. The duplicated values should be compiled into another list which the function will return. No matter how many times a word is duplicated, it should only be added once to the duplicates list. NB: Only write the function. Do not call it. For example: Test Result random_words = ("remember","snakes","nappy","rough","dusty","judicious","brainy","shop","light","straw","quickest", "adventurous","yielding","grandiose","replace","fat","wipe","happy","brainy","shop","light","straw", "quickest","adventurous","yielding","grandiose","motion","gaudy","precede","medical","park","flowers", "noiseless","blade","hanging","whistle","event","slip") print(find_duplicates(sorted(random_words))) ['adventurous', 'brainy', 'grandiose', 'light', 'quickest', 'shop', 'straw', 'yielding']…arrow_forward
- 3. Write the remove_evens() function that receives a list of integers as a parameter and returns a new list of integers containing only the odd numbers from the original list. Ex1) If n = [1, 2, 3, 4, 5, 6], remove_evens(n) returns [1, 3, 5]. Ex2) If n = [2, 4, 8], remov move_evens(n) returns [].arrow_forwardPascal triangle! write a function(in OCaml) val nextpascalrow : int list -> int list = that given a list of integers that correspond to a row of the pascal triangle, it calculates the next row of the pascal triangle. # nextpascalrow [1; 6; 15; 20; 15; 6; 1];; - : int list = [1; 7; 21; 35; 35; 21; 7; 1]arrow_forwardOCAML programming Pascal triangle Write a function val nextpascalrow : int list -> int list = <fun> that given a list of integers that correspond to a row of the pascal triangle, it calculates the next row of the pascal triangle. # nextpascalrow [1; 6; 15; 20; 15; 6; 1];;- : int list = [1; 7; 21; 35; 35; 21; 7; 1]arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education