I wrote the following code in order to apply a function for two lists
which are part of a list of lists but for some reason I’m getting #<void> values in the result.
The code:
(define (applyFunc list)
(cond ((null? list) ())
((null? (cdr list)) (car list))
(else (cons (func (car list) (car (cdr list)))
(applyFunc (cdr (cdr list)))))))
func is a function that applies a function on two given lists
What I get from tracing my code is:
>(applyFunc '((1) (1 1) (1 1 1) (1 1 1 1)))
> (applyFunc '((1 1 1) (1 1 1 1)))
> >(applyFunc '())
< <'()
< '(#<void>)
<'(#<void> #<void>)
(#<void> #<void>)
[assuming the input was '((1) (1 1) (1 1 1) (1 1 1 1))]
I agree with Oscar, above. The main problem with your code was that on the empty case, you were returning
()instead of'().In terms of your naming conventions,
listshould technically run just fine, but, as mentioned by Oscar, it is generally considered bad to run the risk of overwriting a built-in procedure.I updated the code by changing the
()to a'(), and it ran flawlessly.