Write a Racket function named listlen that takes a list as a parameter and evaluates to the number of elements in the list. For example (listlen empty) should evaluate to 0 and (listlen '(1 2 3)) should eveluate to 3.
We defined listlen function using define keyword and listpara is the variable decalred for the list parameters and empty? checks if the list is empty and return 0 if not it will return the length of the list and length is a predefined function
Racket code:
#lang racket
(define (listlen listpara)
(cond
[(empty? listpara) 0]
[else (length(listpara))]
)
)
Sample outputs:
> (listlen empty)
0
> (listlen (list 1 2 3 4))
4
Get Answers For Free
Most questions answered within 1 hours.