Is there an alternative way of writing the make-list function in Scheme (R5RS)? I am trying to create a function where the value repeats itself in the list based on the given size.
So my expected output should be:
(print 5 5) --> (5 5 5 5 5)
(print Ana 3) --> (Ana Ana Ana)
If the parameters are switched, return an empty list (print 3 Ana) --> '()
I am doing this through recursion with a helper function and wanted to use either 'append' or 'cons'
(define print-helper (lambda (value size)
(if (null? value)
0 ;size is zero
(print-helper (append(+ value 1) (cdr size)))
)))
(define print (lambda (value size)
(if not(number? value))
'() ;return
(print-helper value size)
))
sizeis 0, notvalue.consto construct a list step by stepconsorappend, not around the call.sizewhen recursing, don't add 1.not.sizeis a number, notvalue.