5. A functional language could use some data structure other than the list. For
ID: 3703439 • Letter: 5
Question
5. A functional language could use some data structure other than the list. For example, it could use sequences of symbols. What primitives would such a language have in place of the CAR, CDR, and CONS primitives of Scheme? What does the following Scheme function do? 8. (define (y s lis) (cond (null? lis) 0) ((equal? s (car lis)) lis) (else (y s (cdr lis) 9. What does the following Scheme function do? (define (x lis) cond (null? lis) 0) (not (list? (car lis)) cond ((eq? (car lis) nil) (x (cdr lis) else (+ 1 (x (edr lis))) (else (+ (x (car lis) (x (cdr lis)))Explanation / Answer
Answer 5: Following are the primitives that are used by a functional language ML in place of CAR, CDR, CONS of the scheme language:
All of the given three functions in scheme are list based functions.
CONS function: This function is used to concatenate two lists. Same output will be generated by :: in ML.
CAR function: This function is used to compute the HEAD of a list that means first value of the list. Same output will be generated by hd in ML.
CDR function: This function is used to compute the TAIL of the list, which means all the values present in the list except HEAD. Same output will be generated by t1 in ML.
Answer 8:
In the given function, y returns the given list with the leading element (top element) deleted up elements but it does not include the first occurrence of the first given parameter.
Answer 9:
In the given function, x returns the number of elements present in the given list.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.