Exercise DD: (fourth-element L The fourth-element function takes a list L and re
ID: 3727581 • Letter: E
Question
Exercise DD: (fourth-element L The fourth-element function takes a list L and returns its fourth element. Of course, not all lists have four or more elements, if L is a list that doesn't, the empty list should be returned. L is not necessarily simple, but you shouldn't handle sublists differently from other elements (i.e., if the fourth element is a sublist, return the whole sublist Code in DrRacket Examples: (fourth-element (list 'a b'c'd'e))>d (fourth-element (list X (list 'y 'z) 'w 'h 1))->M (fourth-element (list (list 'a 'b) (list'c 'd) (list'e ') (list 'g 'h) (list 'i> (list 'g 'h) (fourth-element (list 'a 'c)) => null or emptyExplanation / Answer
Racket is the dialect of Lisp. Whose name stood for "List Processor".
These above given example for fourth-elements will be written in the DrRacket ,as :--
list-ref fuction is used to extract by position of a element in a list in DrRacket.
1). (list-ref (list 'a 'b 'c 'd 'e) 3) ==> d
2). (list-ref (list 'x (list 'y 'z) 'w 'h 'j) 3) ==> h
3). (list-ref (list '(list 'a 'b) '(list 'c 'd) '(list 'e 'f) '(list 'g 'h) '(list 'i 'j) ) 3)==>(list (quote g) (quote h))
4). (list-ref (list 'a 'b ) 3) ==>null or empty
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.